1005 Euler theorem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Input
For each test case:
A single line contains a positive integer a(1 ≤ a ≤ 109).
A single line contains a nonnegative integer, denoting the answer.
题意:给定正整数a,对于任意正整数b,求a mod b有多少种可能的结果
题解:签到题,可知每个小于a/2的非负整数都可以成为模的结果,当b > a时,a mod b等于a本身,因此可以计算出结果。
include<iostream> #include<cstdio> using namespace std; int main() { int t,a; scanf("%d",&t); while (t--) { scanf("%d",&a); printf("%d\n",a - (a / 2) + 1); } }
1011 Kolakoski
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
For each test case:
A single line contains a positive integer n(1 ≤ n ≤ 107).
A single line contains a nonnegative integer, denoting the answer.
#include<iostream> #include<cstdio> using namespace std; int a[10000050]; int main() { int i,j,temp,k,n,t; a[1] = 1; a[2] = 2; a[3] = 2; i = 3;j = 4;temp = 1; while (j <= 10000050) { for (k = 1;k <= a[i];k++) { a[j] = temp; j++; } i++; temp = 3 - temp; } scanf("%d",&t); while (t--) { scanf("%d",&n); printf("%d\n",a[n]); } }
1008 Hard challenge
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
For each test case:
The first line contains a positive integer n(1 ≤ n ≤ 5 × 104).
The next n lines, the i-th line contains three integers xi,yi,vali(|xi|,|yi|≤109,1≤vali≤104).
A single line contains a nonnegative integer, denoting the answer.
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; struct node { int x,y; double angle; long long val; }; node a[500050]; int cmp(node x,node y) { return x.angle < y.angle; } int main() { int t,n,i; scanf("%d",&t); while (t--) { scanf("%d",&n); for (i = 1;i <= n;i++) { scanf("%d%d%lld",&a[i].x,&a[i].y,&a[i].val); if (a[i].x != 0) a[i].angle = atan(1.0 * a[i].y / a[i].x); else a[i].angle = 3.14159265 / 2; } sort(a + 1,a + n + 1,cmp); long long l = 0,r = 0; for (i = 1;i <= n;i++) { if (a[i].x >= 0) r = r + a[i].val; else l = l + a[i].val; } long long ans = l * r; for (i = 1;i <= n;i++) { if (a[i].x >= 0) { l = l + a[i].val; r = r - a[i].val; } else { l = l - a[i].val; r = r + a[i].val; } if (l * r > ans) ans = l * r; } printf("%lld\n",ans); } }
1010 Just do it
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
For each test case:
The first line contains two positive integers n,m(1 ≤ n ≤ 2 × 105,1 ≤ m ≤ 109).
The second line contains n nonnegative integers a1...n(0 ≤ ai ≤ 230−1).
A single line contains n nonnegative integers, denoting the final sequence.
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int t,n,m,i,k; int a[200050]; scanf("%d",&t); while (t--) { scanf("%d%d",&n,&m); for (i = 1;i <= n;i++) scanf("%d",&a[i]); k = 1; while (k * 4 <= m) k = k * 4; while (m > 0) { while (m >= k) { for (i = k + 1;i <= n;i++) a[i] = a[i] ^ a[i - k]; m = m - k; } k = k / 4; } for (i = 1;i <= n;i++) { printf("%d",a[i]); if (i != n) printf(" "); else printf("\n"); } } }