标签:color 题解 long += swap 一个 1.4 int bsp
Winner winner ,chicken dinner!
水题
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N = 110; 5 6 int main() { 7 cout << "Winner winner ,chicken dinner!" << endl; 8 return 0; 9 }
1 6 3 1 2 2 1 2
4 3 6 5 2 1
以下题解等下写。。。。。
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N = 110; 5 6 int main() { 7 int T, n, q; 8 cin >> T; 9 while(T--) { 10 cin >> n >> q; 11 int flag, x; 12 int a = 0, b = 0; 13 while(q --) { 14 cin >> flag; 15 if(flag == 1) { 16 scanf("%d",&x); 17 a = (n+a-x)%n; 18 b = (n+b-x)%n; 19 if(x&1) swap(a,b); 20 } else { 21 a = (a+n-1)%n; 22 b = (b+n+1)%n; 23 swap(a,b); 24 } 25 } 26 for (int i = 1;i <= n; i ++) { 27 if (i&1)printf("%d%c",(a+i-1+n)%n+1,(i==n?‘\n‘:‘ ‘)); 28 else printf("%d%c",(b+i-1+n)%n+1,(i==n?‘\n‘:‘ ‘)); 29 } 30 } 31 return 0; 32 }
2 10 4 7 8 3 9
0 5
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N = 110; 5 6 int main() { 7 int q, t, L , T; 8 cin >> q; 9 while(q--) { 10 cin >> L >> t >> T; 11 int a = T, b = T - t; 12 a %= (2*L); 13 b %= (2*L); 14 // printf("%d %d\n",a,b); 15 if(a > L) a = 2*L - a; 16 if(b <= L) b = L - b; 17 else if(b > L) b = b - L; 18 printf("%d\n",abs(a-b)); 19 } 20 return 0; 21 }
1 3 2 0 2 0 0 0 2 0 0 0
0 2 4 0 0 2 0 0 0
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 typedef vector<ll> vec; 5 typedef vector<vec> mat; 6 const ll Mod = 10; 7 ll t, len, k; 8 int b[33][33]; 9 mat mul(mat &A, mat &B) { 10 mat C(A.size(), vec(B[0].size())); 11 for(int i = 0; i < A.size(); i ++) { 12 for(int k = 0; k < B.size(); k ++) { 13 for(int j = 0; j < B[0].size(); j ++) { 14 C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % Mod; 15 } 16 } 17 } 18 return C; 19 } 20 mat add(mat A, mat B) { 21 mat C(len, vec(len)); 22 for(int i = 0; i < len; i ++) { 23 for(int j = 0; j < len; j ++) { 24 C[i][j] = (A[i][j] + B[i][j]) % Mod; 25 } 26 } 27 return C; 28 } 29 mat pow(mat A, ll n) { 30 mat B(A.size(), vec(A.size())); 31 for(int i = 0; i < A.size(); i ++) { 32 B[i][i] = 1; 33 } 34 while(n > 0) { 35 if(n&1) B = mul(B,A); 36 A = mul(A,A); 37 n >>= 1; 38 } 39 return B; 40 } 41 mat dfs(mat A, ll tmp) { 42 if(tmp == 1) return A; 43 mat B(len, vec(len)); 44 mat C(len, vec(len)); 45 if(tmp%2 == 0) { 46 B = dfs(A, tmp/2); 47 C = pow(A, tmp/2); 48 return add(mul(B,C), B); 49 } else { 50 B = dfs(A, tmp/2); 51 C = pow(A, tmp/2); 52 return add(pow(A, tmp), add(B, mul(C, B))); 53 //add(pow(A,tmp),add(mul(pow(A,tmp/2),dfs(A,tmp/2)), dfs(A,tmp/2))); 54 } 55 } 56 int main() { 57 58 cin >> t; 59 while(t--) { 60 cin >> len >> k; 61 mat A(len, vec(len)); 62 mat B(len, vec(len)); 63 for(int i = 0; i < len; i ++) { 64 for(int j = 0; j < len; j ++) { 65 cin >> A[i][j]; 66 b[i][j] = A[i][j]%10; 67 } 68 } 69 //B = add(A,A); 70 B = dfs(A, k); 71 for(int i = 0; i < len; i ++) { 72 for(int j = 0; j < len-1; j ++) { 73 printf("%d ",B[i][j]); 74 } 75 printf("%d\n",B[i][len-1]); 76 } 77 } 78 return 0; 79 }
1 3 1 2 3
2
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N = 1e6+10; 5 int a[N], pre[N], sum[N]; 6 int main() { 7 int T; 8 cin>> T; 9 while(T--) { 10 int n; 11 cin >> n; 12 memset(sum, 0, sizeof(sum)); 13 memset(pre, 0, sizeof(pre)); 14 for(int i = 1; i <= n; i ++) cin >> a[i]; 15 for(int i = 1; i <= n; i ++) { 16 sum[i] = max(sum[i-1], a[i]); 17 } 18 for(int i = n; i > 0; i --) { 19 pre[i] = max(pre[i+1], a[i]); 20 } 21 int MAX = -1; 22 for(int i = 2; i <= n; i ++){ 23 MAX = max(MAX, abs(pre[i]-sum[i-1])); 24 } 25 printf("%d\n",MAX); 26 } 27 return 0; 28 }
1 5 1 2 4 4 1 4 1 2 3 4
6 12 15 12
1 #include<bits/stdc++.h> 2 #define ll long long 3 #define lson l,m,rt<<1 4 #define rson m+1,r,rt<<1|1 5 using namespace std; 6 map<int,ll>mp; 7 const int N=1e5+10; 8 int n,j,t,a,q; 9 int ans[N],ls[N],vis[N],tree[N<<2]; 10 void mk(int rt) { 11 tree[rt]= __gcd(tree[rt<<1],tree[rt<<1|1]); 12 } 13 void init(){ 14 mp.clear(); 15 cin >> n; 16 for(int i = 1;i <= n;i ++) cin >> ans[i]; 17 for(int i = 1;i <= n;i ++) { 18 for(vis[i] = ans[i],j = ls[i]=i; j; j=ls[j]-1){ 19 vis[j]=__gcd(vis[j],ans[i]); 20 while(ls[j] > 1&& __gcd(ans[i], vis[ls[j]-1]) == __gcd(ans[i], vis[j])) 21 ls[j] = ls[ls[j]-1]; 22 mp[vis[j]] += j-ls[j]+1; 23 } 24 } 25 } 26 27 void build(int l,int r,int rt){ 28 if(l == r) { 29 tree[rt] = ans[l]; 30 return; 31 } 32 int m = (l+r) >> 1; 33 build(lson); 34 build(rson); 35 mk(rt); 36 } 37 38 int main(){ 39 cin >> t; 40 while(t--){ 41 init(); 42 build(1, n, 1); 43 cin >> q; 44 while(q--){ 45 cin >> a; 46 ll len = n*(n+1)/2; 47 printf("%lld\n",len-mp[a]); 48 } 49 } 50 return 0; 51 }
233 233333333333333333333333333333333333333333333333333333333
3 QAQ
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int main(){ 5 string s; 6 while(cin >> s){ 7 if(s.length() > 10){ 8 cout << "QAQ\n"; 9 continue; 10 } 11 ll ans = 0; 12 for(int i = 0; i < s.length(); i++){ 13 ans = ans*10 + (ll)(s[i]-‘0‘); 14 } 15 if(ans == 1) { 16 printf("0\n"); 17 continue; 18 } 19 bool flag = false; 20 for(int i = 1; i <= 5; i ++){ 21 ans = sqrt(ans); 22 if(ans == 1LL){ 23 flag = true; 24 cout << i << endl; 25 break; 26 } 27 } 28 if(!flag) printf("QAQ\n"); 29 } 30 return 0; 31 }
标签:color 题解 long += swap 一个 1.4 int bsp
原文地址:http://www.cnblogs.com/xingkongyihao/p/7857367.html