wenbao与思维(大白书)
--------------------------------------------------------------------------------------------------------------------------------
墓地雕塑
添加墓地,使移动最少
1 #include <iostream> 2 #include <algorithm> 3 #include <cmath> 4 using namespace std; 5 int main(){ 6 int n, m; 7 while(scanf("%d%d", &n, &m) == 2){ 8 double sum = 0; 9 for(int i = 1; i < n; i++){ 10 double x = (double)i/n*(n+m); 11 sum += fabs(x - floor(x + 0.5))/(n+m); 12 } 13 sum*=10000; 14 printf("%.4lf\n", sum); 15 } 16 return 0; 17 }
四舍五入:
floor(x+0.5)
--------------------------------------------------------------------------------------------------------------------------------
蚂蚁
套路题,要知道碰到看成穿过去,可以得出末态的坐标,又易知他们的相对位置是不变的,所以只要推出第一个蚂蚁的坐标相当于所有的坐标都有了!!!
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&page=show_problem&problem=1822
碰到掉头
1 #include <iostream> 2 #include <algorithm> 3 #include <string.h> 4 #include <cmath> 5 using namespace std; 6 const int maxn = 10009; 7 const char Str[][10] = {"L", "Turning", "R"}; 8 int b[10009]; 9 struct Node{ 10 int x, y, z; 11 }T[10009], W[10009]; 12 int cmp(Node a, Node b){ 13 return a.x < b.x; 14 } 15 int main(){ 16 int xx, num = 1; 17 char str; 18 scanf("%d", &xx); 19 while(xx--){ 20 int l, t, n; 21 scanf("%d%d%d", &l, &t, &n); 22 for(int i = 0; i < n; i++){ 23 scanf("%d %c", &T[i].x, &str); 24 if(str == 'R') W[i].y = T[i].y = 1; 25 else W[i].y = T[i].y = -1; 26 W[i].x = T[i].x + T[i].y*t; 27 T[i].z = i; 28 } 29 sort(T, T+n, cmp); 30 for(int i = 0; i < n; i++){ 31 b[T[i].z] = i; 32 } 33 sort(W, W+n, cmp); 34 for(int i = 0; i < n-1; i++){ 35 if(W[i].x == W[i+1].x){ 36 W[i].y = W[i+1].y = 0; 37 } 38 } 39 printf("Case #%d:\n", num++); 40 for(int i = 0; i < n; i++){ 41 int x = b[i]; 42 if(W[x].x < 0 || W[x].x > l){ 43 printf("Fell off\n"); 44 }else{ 45 printf("%d %s\n", W[x].x, Str[W[x].y+1]); 46 } 47 } 48 printf("\n"); 49 } 50 return 0; 51 }
大神级别
1 #include <iostream> 2 #include <algorithm> 3 #include <string.h> 4 #include <cmath> 5 using namespace std; 6 const int maxn = 10009; 7 const char Str[][10] = {"L", "Turning", "R"}; 8 int b[10009]; 9 struct Node{ 10 int x, y, z; 11 bool operator < (const Node& a) const{ 12 return x < a.x; 13 } 14 }T[maxn], W[maxn]; 15 int main(){ 16 int xx, num = 1; 17 char str; 18 scanf("%d", &xx); 19 while(xx--){ 20 int l, t, n, xx, yy; 21 scanf("%d%d%d", &l, &t, &n); 22 for(int i = 0; i < n; i++){ 23 scanf("%d %c", &xx, &str); 24 yy = (str == 'R' ? 1 : -1); 25 T[i] = (Node){xx, yy, i}; 26 W[i] = (Node){xx+yy*t, yy, 0}; 27 } 28 sort(T, T+n); 29 for(int i = 0; i < n; i++){ 30 b[T[i].z] = i; 31 } 32 sort(W, W+n); 33 for(int i = 0; i < n-1; i++){ 34 if(W[i].x == W[i+1].x){ 35 W[i].y = W[i+1].y = 0; 36 } 37 } 38 printf("Case #%d:\n", num++); 39 for(int i = 0; i < n; i++){ 40 int x = b[i]; 41 if(W[x].x < 0 || W[x].x > l){ 42 printf("Fell off\n"); 43 }else{ 44 printf("%d %s\n", W[x].x, Str[W[x].y+1]); 45 } 46 } 47 printf("\n"); 48 } 49 return 0; 50 }
---------------------------------------------------------------------
tccoder上面有一个非常相似的题
http://agc013.contest.atcoder.jp/tasks/agc013_c
不同的是这个题里面的路径是一个圈
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 using namespace std; 5 #define ll long long 6 const int maxn = 1e5+10; 7 ll a[maxn]; 8 int main(){ 9 ll n, l, t, x, y, num = 0; 10 scanf("%lld%lld%lld", &n, &l, &t); 11 for(int i = 0; i < n; ++i){ 12 scanf("%lld%lld", &x, &y); 13 a[i] = x + (y == 1 ? t : -t); 14 num += a[i]/l; 15 a[i] %= l; 16 if(a[i] < 0) a[i] += l, num --; 17 } 18 num %= n; 19 sort(a, a+n); 20 for(int i = 0; i < n; ++i){ 21 if(i == n-1) printf("%lld\n", a[(i+num+n)%n]); 22 else printf("%lld ", a[(i+num+n)%n]); 23 } 24 return 0; 25 }
--------------------------------------------------------------------------------------------------------------------------------
最多立方体
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=12&problem=996&mosmsg=Submission+received+with+ID+2127767
1 #include <iostream> 2 using namespace std; 3 #define REP(i, n) for(int i = 0; i < n; i++) 4 const int maxn = 10; 5 char map[maxn][maxn][maxn], T[maxn][maxn][maxn]; 6 int n; 7 char read(){ 8 char ch; 9 for(;;){ 10 ch = getchar(); 11 if(ch >= 'A' && ch <= 'Z' || ch == '.') return ch; 12 } 13 } 14 void get(int i, int j, int k, int t, int &x, int &y, int &z){ 15 if(i == 0) {x = n-1-t, y = k, z = n-1-j;} 16 if(i == 1) {x = k, y = t, z = n-1-j;} 17 if(i == 2) {x = t, y = n-1-k, z = n-1-j;} 18 if(i == 3) {x = n-1-k, y = n-1-t, z = n-1-j;} 19 if(i == 4) {x = j, y = k, z = n-1-t;} 20 if(i == 5) {x = n-1-j, y = k, z = t;} 21 } 22 int main(){ 23 while(scanf("%d", &n) && n){ 24 REP(i, n) REP(j, 6) REP(k, n) map[j][i][k] = read(); 25 REP(i, n) REP(j, n) REP(k, n) T[i][j][k] = '*'; 26 REP(i, 6) REP(j, n) REP(k, n) if(map[i][j][k] == '.'){ 27 REP(t, n){ 28 int x, y, z; 29 get(i, j, k, t, x, y, z); 30 T[x][y][z] = '.'; 31 } 32 } 33 int sum = 0; 34 while(1){ 35 bool flag = true; 36 REP(i, 6) REP(j, n) REP(k, n) if(map[i][j][k] != '.'){ 37 REP(t, n){ 38 int x, y, z; 39 get(i, j, k, t, x, y, z); 40 if(T[x][y][z] == '.') continue; 41 if(T[x][y][z] == '*'){ 42 T[x][y][z] = map[i][j][k]; 43 break; 44 } 45 if(map[i][j][k] == T[x][y][z]) break; 46 T[x][y][z] = '.'; 47 flag = false; 48 } 49 } 50 if(flag) break; 51 } 52 REP(i, n) REP(j, n) REP(k, n) if(T[i][j][k] != '.') sum ++; 53 printf("Maximum weight: %d gram(s)\n", sum); 54 } 55 return 0; 56 }
学习到了好多
字符的输入,坐标化。。。。。
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
只有不断学习才能进步!