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<iostream> #include<math.h> #include <memory.h> using namespace std; int OutPx =0; int OutPxLenth=0; void SetValue(int px); void SetValue(int px) { if (px==OutPx) { OutPxLenth++; } else { cout << OutPx << ' ' << OutPxLenth << endl; OutPx = px; OutPxLenth = 1; } } int main() { int colNum; cin >> colNum; while (colNum != 0) { cout << colNum << endl; int RLEPx; long RLELength; int* RLERol1 = new int[colNum]; int* RLERol2 = new int[colNum]; int* RLERolCur = new int[colNum]; int CulColIndex = 0;//列索引 int CurRowIndex = 0; cin >> RLEPx >> RLELength; while (RLEPx != 0 || RLELength != 0) { for (int i = 0; i < RLELength; i++) { RLERolCur[CulColIndex] = RLEPx; CulColIndex++; //如果输入行输入结束,则换行并计算倒数第二行的值 有三种情况 //第一行结束不计算,第二行结束,计算第一行 --下左右的的差 //第三行结束,计算第二行 --上下左右的差 if (CulColIndex == colNum) { if (CurRowIndex == 0) { } else if (CurRowIndex == 1) { int a = abs(RLERol2[0] - RLERol2[1]);//右 int a2 = abs(RLERol2[0] - RLERolCur[0]);//下 a = a > a2 ? a : a2; a2 = abs(RLERol2[0] - RLERolCur[1]);//下右 a = a > a2 ? a : a2; OutPx = a; OutPxLenth = 1; for (int rol2index = 1; rol2index < colNum - 1; rol2index++) { a = abs(RLERol2[rol2index] - RLERol2[rol2index + 1]);//右 a2 = abs(RLERol2[rol2index] - RLERol2[rol2index - 1]);//左 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERolCur[rol2index - 1]);//下左 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERolCur[rol2index]);//下 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERolCur[rol2index + 1]);//下右 a = a > a2 ? a : a2; SetValue(a); } a = abs(RLERol2[colNum - 1] - RLERol2[colNum - 2]);//左 a2 = abs(RLERol2[colNum - 1] - RLERolCur[colNum - 1]);//下 a = a > a2 ? a : a2; a2 = abs(RLERol2[colNum - 1] - RLERolCur[colNum - 2]);//下左 a = a > a2 ? a : a2; SetValue(a); } else { if (i >= 3 * colNum) { int skipNum = ((RLELength-i) / colNum)*colNum; i += skipNum; if (0 == OutPx) { OutPxLenth += skipNum; } else { cout << OutPx << ' ' << OutPxLenth << endl; OutPx = 0; OutPxLenth = skipNum; } } else { int a = abs(RLERol2[0] - RLERol2[1]);//右 int a2 = abs(RLERol2[0] - RLERolCur[0]);//下 a = a > a2 ? a : a2; a2 = abs(RLERol2[0] - RLERolCur[1]);//下右 a = a > a2 ? a : a2; a2 = abs(RLERol2[0] - RLERol1[0]);//上 a = a > a2 ? a : a2; a2 = abs(RLERol2[0] - RLERol1[1]);//上右 a = a > a2 ? a : a2; SetValue(a); for (int rol2index = 1; rol2index < colNum - 1; rol2index++) { a = abs(RLERol2[rol2index] - RLERol2[rol2index + 1]);//右 a2 = abs(RLERol2[rol2index] - RLERol2[rol2index - 1]);//左 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERolCur[rol2index - 1]);//下左 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERolCur[rol2index]);//下 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERolCur[rol2index + 1]);//下右 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERol1[rol2index - 1]);//上左 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERol1[rol2index]);//上 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERol1[rol2index + 1]);//上右 a = a > a2 ? a : a2; SetValue(a); } a = abs(RLERol2[colNum - 1] - RLERol2[colNum - 2]);//左 a2 = abs(RLERol2[colNum - 1] - RLERolCur[colNum - 1]);//下 a = a > a2 ? a : a2; a2 = abs(RLERol2[colNum - 1] - RLERolCur[colNum - 2]);//下左 a = a > a2 ? a : a2; a2 = abs(RLERol2[colNum - 1] - RLERol1[colNum - 1]);//上 a = a > a2 ? a : a2; a2 = abs(RLERol2[colNum - 1] - RLERol1[colNum - 2]);//上左 a = a > a2 ? a : a2; SetValue(a); } } //换行 memcpy(RLERol1, RLERol2, colNum * sizeof(int)); memcpy(RLERol2, RLERolCur, colNum * sizeof(int)); //RLERol1 = RLERol2; //RLERol2 = RLERolCur; CulColIndex = 0; CurRowIndex++; } } cin >> RLEPx >> RLELength; } //最后一列有两种情况,1空行 CurRowIndex=0 if (CulColIndex == 0 && CurRowIndex == 0) { int a = abs(RLERol2[0] - RLERol2[1]);//右 int a2; SetValue(a); for (int rol2index = 1; rol2index < colNum - 1; rol2index++) { a = abs(RLERol2[rol2index] - RLERol2[rol2index + 1]);//右 a2 = abs(RLERol2[rol2index] - RLERol2[rol2index - 1]);//左 a = a > a2 ? a : a2; SetValue(a); } if (colNum > 1) { a = abs(RLERol2[colNum - 1] - RLERol2[colNum - 2]);//左 SetValue(a); } } else if (CulColIndex == 0 && CurRowIndex > 0) { int a = abs(RLERol2[0] - RLERol2[1]);//右 int a2 = abs(RLERol2[0] - RLERol1[0]);//上 a = a > a2 ? a : a2; a2 = abs(RLERol2[0] - RLERol1[1]);//上右 a = a > a2 ? a : a2; SetValue(a); for (int rol2index = 1; rol2index < colNum - 1; rol2index++) { a = abs(RLERol2[rol2index] - RLERol2[rol2index + 1]);//右 a2 = abs(RLERol2[rol2index] - RLERol2[rol2index - 1]);//左 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERol1[rol2index - 1]);//上左 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERol1[rol2index]);//上 a = a > a2 ? a : a2; a2 = abs(RLERol2[rol2index] - RLERol1[rol2index + 1]);//上右 a = a > a2 ? a : a2; SetValue(a); } if (colNum > 1) { a = abs(RLERol2[colNum - 1] - RLERol2[colNum - 2]);//左 a2 = abs(RLERol2[colNum - 1] - RLERol1[colNum - 1]);//上 a = a > a2 ? a : a2; a2 = abs(RLERol2[colNum - 1] - RLERol1[colNum - 2]);//上左 a = a > a2 ? a : a2; SetValue(a); } } else { int a = abs(RLERolCur[0] - RLERolCur[1]);//右 int a2 = abs(RLERolCur[0] - RLERol2[0]);//上 a = a > a2 ? a : a2; a2 = abs(RLERolCur[0] - RLERol2[1]);//上右 a = a > a2 ? a : a2; SetValue(a); for (int rol2index = 1; rol2index < CulColIndex; rol2index++) { a = abs(RLERolCur[rol2index] - RLERolCur[rol2index + 1]);//右 a2 = abs(RLERolCur[rol2index] - RLERolCur[rol2index - 1]);//左 a = a > a2 ? a : a2; a2 = abs(RLERolCur[rol2index] - RLERol2[rol2index - 1]);//上左 a = a > a2 ? a : a2; a2 = abs(RLERolCur[rol2index] - RLERol2[rol2index]);//上 a = a > a2 ? a : a2; a2 = abs(RLERolCur[rol2index] - RLERol2[rol2index + 1]);//上右 a = a > a2 ? a : a2; SetValue(a); } if (CulColIndex > 0) { a = abs(RLERolCur[CulColIndex] - RLERolCur[CulColIndex - 1]);//左 a2 = abs(RLERolCur[CulColIndex] - RLERol2[CulColIndex - 0]);//上 a = a > a2 ? a : a2; a2 = abs(RLERolCur[CulColIndex] - RLERol2[CulColIndex - 1]);//上左 a = a > a2 ? a : a2; SetValue(a); } } cout << OutPx << ' ' << OutPxLenth << endl; OutPx = 0; OutPxLenth = 0; cin >> colNum; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator