sgu168:猥琐输入输出的应用 + 简单dp
用getchar和putchar进行输入输出,会比scanf和printf快很多很多。
输入
1
2 char t;
3 scanf("%d%d\n", &m, &n);
4 memset(B, 1, sizeof(B));
5 for(i = 1; i <= m; i++) {
6 for(j = 1; j <= n; j++) {
7 minus = 1;
8 tmp = 0;
9 t = getchar();
10 while(t == ' ') t = getchar();
11 if(t == '-') {
12 t = getchar();
13 minus = -1;
14 }
15 while(t != ' ' && t != 10) {
16 tmp = tmp * 10 + t - '0';
17 t = getchar();
18 }
19 A[i][j] = tmp * minus;
20 //scanf("%d", &A[i][j]);
21 }
22 while(t != 10) {t = getchar();}
23 }
输出
1
2 void print(int t)
3 {
4 if(t > -10 && t < 10) {
5 printf("%d",t);
6 return;
7 }
8 if(t < 0) {
9 putchar('-');
10 t = -t;
11 }
12 top = 0;
13 while(t > 0) {
14 out[top++] = t % 10;
15 t /= 10;
16 }
17 for(int i = top - 1;i >= 0;i--) {
18 putchar('0' + out[i]);
19 }
20 }
我sb了好久。。。。没发现还有负数
dp过程
for(int i = n; i >= 1; i--)
for(int j = m; j >= 1; j--)
B[j][i] = min(min(A[j][i], B[j][i + 1]), min(B[j + 1][i], B[j - 1][i + 1]));
977046 03.01.10 15:41 schindlerlee 168 .CPP Accepted 958 ms 8183 kb