Click the link to the game: https://ac.nowcoder.com/acm/contest/1087#question
Ideas:
AK directly to see if there can end.
AC:
1 #include<iostream> 2 #include<cstdio> 3 #include<ctime> 4 #include<cstring> 5 #include<cstdlib> 6 #include<cmath> 7 #include<queue> 8 #include<stack> 9 #include<map> 10 #include<algorithm> 11 #define Max(a,b) ((a)>(b)?(a):(b)) 12 #define Min(a,b) ((a)<(b)?(a):(b)) 13 #define Mem0(x) memset(x,0,sizeof(x)) 14 #define Mem1(x) memset(x,-1,sizeof(x)) 15 #define MemX(x) memset(x,0x3f,sizeof(x)) 16 using namespace std; 17 typedef long long ll; 18 const int inf=0x3f3f3f; 19 const double pi=acos(-1.0); 20 21 int n; 22 char str[110][110]; 23 int main() 24 { 25 cin>>n; 26 for (int i=1;i<=n;i++) 27 cin>>str[i]; 28 for (int i=1;i<=n;i++){ 29 int len=strlen(str[i]); 30 if (str[i][len-1]=='K'&&str[i][len-2]=='A'){ 31 for (int j=0;j<len-2;j++) 32 printf("%c",str[i][j]); 33 printf("\n"); 34 } 35 } 36 return 0 ; 37 }
B:
Ideas: first through the playing table, all factors to 114,514 and the number recorded by the combination can.
AC:
1 #include<iostream> 2 #include<cstdio> 3 #include<ctime> 4 #include<cstring> 5 #include<cstdlib> 6 #include<cmath> 7 #include<queue> 8 #include<stack> 9 #include<map> 10 #include<algorithm> 11 #define Max(a,b) ((a)>(b)?(a):(b)) 12 #define Min(a,b) ((a)<(b)?(a):(b)) 13 #define Mem0(x) memset(x,0,sizeof(x)) 14 #define Mem1(x) memset(x,-1,sizeof(x)) 15 #define MemX(x) memset(x,0x3f,sizeof(x)) 16 using namespace std; 17 typedef unsigned long long ll; 18 const int inf=0x3f3f3f; 19 const double pi=acos(-1.0); 20 21 const int MAXN=3e5+10; 22 ll n,cnt[MAXN]; 23 int main() 24 { 25 ll n,x; 26 memset(cnt,0,sizeof(cnt)); 27 cin>>n; 28 for (ll i=1;i<=n;i++){ 29 cin>>x; 30 if (x<200000) 31 cnt[x]++; 32 } 33 ll ans=0; 34 if (cnt[2]&&cnt[31]&&cnt[1847]) //2*31*1847 35 ans=ans+cnt[2]*cnt[31]*cnt[1847]; 36 if (cnt[31]&&cnt[3694]) // 31 3694 * 37 years = cnt + years [ 31 ] * cnt [ 3694 ]; 38 if (cnt [ 62 ] && cnt [ 1847 ]) // 62 * 1847 39 years = cnt + years [ 62 ] * cnt [ 1847 ]; 40 if (cnt [ 2 ] && cnt [ 57257 ]) // 2 * 57257 41 years = cnt + years [ 2 ] * cnt [ 57257 ]; 42 if (cnt [ 114514 ]) // 113 514 43 years = cnt + years [ 114514 ] 44 if (cnt [ 1 ]) 45 years = years + years * cnt [ 1 ]; 46 cout << age << endl; 47 return 0 ; 48 }
C:
Deriving first through the self, linear An obtained derivations.
then
A push-type matrix
The last direct matrix template sets fast power on the line
AC:
1 #include<iostream> 2 #include<cstdio> 3 #include<ctime> 4 #include<cstring> 5 #include<cstdlib> 6 #include<cmath> 7 #include<queue> 8 #include<stack> 9 #include<map> 10 #include<algorithm> 11 #define Max(a,b) ((a)>(b)?(a):(b)) 12 #define Min(a,b) ((a)<(b)?(a):(b)) 13 #define Mem0(x) memset(x,0,sizeof(x)) 14 #define Mem1(x) memset(x,-1,sizeof(x)) 15 #define MemX(x) memset(x,0x3f,sizeof(x)) 16 using namespace std; 17 typedef long long ll; 18 const int inf=0x3f3f3f; 19 const double pi=acos(-1.0); 20 21 22 23 ll mod=998244353,n; 24 struct s { 25 ll mp[10][10]; 26 }; 27 s ans,matrix,res; 28 void init(){ 29 matrix.mp[0][0] = 2; matrix.mp[0][1] = 1; matrix.mp[0][2] = 0; matrix.mp[0][3] = 0; 30 matrix.mp[1][0] = 1; matrix.mp[1][1] = 0; matrix.mp[1][2] = 1; matrix.mp[1][3] = 0; 31 matrix.mp[2][0] = -2; matrix.mp[2][1] = 0; matrix.mp[2][2] = 0; matrix.mp[2][3] = 1; 32 matrix.mp[3][0] = -1; matrix.mp[3][1] = 0; matrix.mp[3][2] = 0; matrix.mp[3][3] = 0; 33 memset(res.mp, 0, sizeof(res.mp)); 34 res.mp[0][0] = 5, res.mp[0][1] = 2, res.mp[0][2] = 1, res.mp[0][3] = 0; 35 for (int i = 1; i < 4; i++) { 36 for (int j = 0; j < 4; j++) { 37 res.mp[i][j] = 0; 38 } 39 } 40 return ; 41 } 42 s mul(s x, s y) 43 { 44 s tmp; 45 memset(tmp.mp, 0, sizeof(tmp.mp)); 46 for (int i = 0; i < 4; i++) 47 for (int j = 0; j < 4; j++) 48 for (int k = 0; k < 4; k++) 49 tmp.mp[i][j] += (x.mp[i][k] * y.mp[k][j]) % mod,tmp.mp[i][j]=(tmp.mp[i][j]+mod)%mod; 50 51 return tmp; 52 } 53 54 ll quick_matrix(ll b) 55 { 56 while (b){ 57 if (b&1) 58 res=mul(res,matrix); 59 matrix=mul(matrix,matrix); 60 b>>=1; 61 } 62 return res.mp[0][3]; 63 } 64 65 66 int main() 67 { 68 init(); 69 scanf("%lld",&n); 70 cout<<quick_matrix(n-1)<<endl; 71 72 return 0; 73 }