POJ1009

来源:互联网 发布:饥荒联机内存优化mod 编辑:程序博客网 时间:2024/06/06 08:49

自己测试都没问题,但提交后却是Wrong Answer,不知道问题出在哪儿。

C++源代码:

//Edge Detection//2017.03.19 by wyj#include  #include  #include#include#includeusing namespace std;int Inmap[1100][2], Outmap[10000][2];int width;int total;int main(){int GetValue(int pos);int GetCode(int pos);int comp(const void*a, const void*b);int pixelout;int In[1100],Out[10000];//输入变换点的下标和对应周围点的下标while (scanf_s("%d", &width) && width){int n = 0, i = 0, j = 0, k = 0, p = 0;while ((cin >> Inmap[i][0] >> Inmap[i][1]) && (Inmap[i][0] || Inmap[i][1])){In[i] = n;//第i个输入变化点的下标n = n + Inmap[i][1];i++;}total = n;for (p = 0;p < i;p++){int row = In[p] / width;int col = In[p] % width;for (int x = row - 1;x <= row + 1;x++)for (int y = col - 1;y <= col + 1;y++){if (x < 0 || y < 0 || y >= width || x*width + y >=total )continue;Out[k++] = x*width + y;}}qsort(Out, k, sizeof(int), comp);Outmap[0][0] = GetCode(0);Outmap[0][1] = 1;int t = 0;for (p = 1;p < k;p++){if (Out[p] == Out[p - 1])continue;pixelout = GetCode(Out[p]);if (pixelout != GetCode(Out[p] - 1)){Outmap[++j][0] = pixelout;Outmap[j-1][1] = Out[p] - t;t += Outmap[j - 1][1];}}Outmap[j][1] = total - t;cout << width << endl;for (k = 0;k <= j;k++)cout << Outmap[k][0] << ' ' << Outmap[k][1] << endl;cout <<"0 0"<< endl;}cout << 0<< endl;return 0;}/*快排比较规则*/int comp(const void*a, const void*b){return *(int*)a - *(int*)b;}/*返回第pos个像素点的像素值*/int GetValue(int pos){int i = 0, p = 0;while (p<=pos)p += Inmap[i++][1];return Inmap[i - 1][0];}/*返回第pos个像素点的编码*/int GetCode(int pos){int code = GetValue(pos);int max(int a, int b, int c, int d, int e);int max(int a, int b, int c, int d, int e, int f, int g, int h);int MaxAbs = 0;int a[8];int k;a[0] = pos - width - 1;a[1] = pos - width;a[2] = pos - width + 1;a[3] = pos - 1;a[4] = pos + 1;a[5] = pos + width - 1;a[6] = pos + width;a[7] = pos + width + 1;for (k = 0;k < 8;k++){if (a[k] < 0 || a[k] >= total)a[k] = pos;}if (pos%width == 0)MaxAbs = max(abs(GetValue(pos) - GetValue(a[1])), abs(GetValue(pos) - GetValue(a[2])),abs(GetValue(pos) - GetValue(a[4])), abs(GetValue(pos) - GetValue(a[6])), abs(GetValue(pos) - GetValue(a[7])));elseif (pos%width == width - 1)MaxAbs = max(abs(GetValue(pos) - GetValue(a[0])), abs(GetValue(pos) - GetValue(a[1])),abs(GetValue(pos) - GetValue(a[3])), abs(GetValue(pos) - GetValue(a[5])), abs(GetValue(pos) - GetValue(a[6])));elseMaxAbs = max(abs(GetValue(pos) - GetValue(a[0])), abs(GetValue(pos) - GetValue(a[1])),abs(GetValue(pos) - GetValue(a[2])), abs(GetValue(pos) - GetValue(a[3])), abs(GetValue(pos) - GetValue(a[4])),abs(GetValue(pos) - GetValue(a[5])), abs(GetValue(pos) - GetValue(a[6])), abs(GetValue(pos) - GetValue(a[7])));return MaxAbs;}int max(int a, int b, int c, int d, int e){if (b > a)a = b;if (c > a)a = c;if (d > a)a = d;if (e > a)a = e;return a;}int max(int a, int b, int c, int d, int e, int f, int g, int h){if (b > a)a = b;if (c > a)a = c;if (d > a)a = d;if (e > a)a = e;if (f > a)a = f;if (g > a)a = g;if (h > a)a = h;return a;}

0 0
原创粉丝点击