Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
[ Runtime Error ] 讨论区给的数据都通过了为啥还这样?大牛帮忙测测吧~#include <stdio.h> #include <stdlib.h> #define MAX 1024 int absi(int x, int y) { return x > y ? x - y : y - x; } int main() { int input[MAX] = {0}; int output[MAX] = {0}; int line; scanf("%d", &line); printf("%d\n", line); while (line > 0) { for (int i = 0; i < line; i++) { input[i] = output[i] = -1; } int value, length; int col = 0, count = 0; int previ = -1, prevo = -1, prevn = 1; int pprevi = -1, pprevo = -1, pprevn = 1; scanf("%d %d", &value, &length); while (value + length > 0) { count = 0; while (length > 0 && count < 2 * line + 2) { int tempo = -1, temp = -1; if (input[col] == -1) { input[col] = value; if (col > 0) { temp = absi(value, input[col - 1]); output[col] = temp > output[col] ? temp : output[col]; output[col - 1] = temp > output[col - 1] ? temp : output[col - 1]; } } else { temp = absi(value, input[col]); tempo = temp > tempo ? temp : tempo; output[col] = temp > output[col] ? temp : output[col]; if (col > 0) { temp = absi(value, input[col - 1]); tempo = temp > tempo ? temp : tempo; output[col - 1] = temp > output[col - 1] ? temp : output[col - 1]; } if (col < line - 1) { temp = absi(value, input[col + 1]); tempo = temp > tempo ? temp : tempo; output[col + 1] = temp > output[col + 1] ? temp : output[col + 1]; } if (previ != -1 && col > 0) { temp = absi(value, previ); tempo = temp > tempo ? temp : tempo; prevo = temp > prevo ? temp : prevo; } if (pprevo != -1) { if (prevo == pprevo) { prevn = pprevn + 1; } else { prevn = 1; printf("%d %d\n", pprevo, pprevn); } } pprevo = prevo; pprevn = prevn; previ = input[col]; prevo = output[col]; input[col] = value; output[col] = tempo; } col = (col + 1) % line; length--; count++; } if (length > 0) { if (prevo == pprevo) { prevn = pprevn + length; } else { prevn = length; printf("%d %d\n", pprevo, pprevn); } pprevo = prevo; pprevn = prevn; col = (col + length) % line; } scanf("%d %d", &value, &length); } for (col = 0; col <= line; col++) { if (pprevo != -1) { if (prevo == pprevo) { prevn = pprevn + 1; } else { printf("%d %d\n", pprevo, pprevn); prevn = 1; } } pprevo = prevo; pprevn = prevn; if (col < line) { previ = input[col]; prevo = output[col]; } } pprevo = pprevo == -1 ? 0 : pprevo; printf("%d %d\n", pprevo, pprevn); printf("0 0\n"); scanf("%d", &line); printf("%d\n", line); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator