poj 1009 这哪是模拟题啊？

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int width;// the width of the Map
int total = 0;//the total num of pixel

struct Map
{
int pos;//position of the pixel
int code;//the code of the pixel
}pixMap[9010];
int mMap[1010][2];

int cmp(const void *a, const void *b)
{
struct Map * x = (struct Map *)a;
struct Map * y = (struct Map *)b;
return x->pos - y->pos;
}
int GetValue(int pos)
{
int i = 0;
int p = 0;
while (p < pos)
{
p += mMap[i ++][1];
}
return mMap[i - 1][0];
}
int GetCode(int pos)
{
int code = GetValue(pos);
int Max = 0;
int row = (pos - 1) / width;//the
int col = (pos - 1) % width;
for (int i = row - 1; i <= row + 1; ++ i)
{
for (int j = col - 1; j <= col + 1; ++ j)
{
int tpos = i * width + j;
if (i < 0 || j < 0 || j >= width || tpos >= total || tpos == pos - 1)
{
continue;
}
int tcode = GetValue(tpos + 1);
if (Max < abs(tcode - code))
{
Max = abs(tcode - code);
}
//pixMap[k].pos = tpos + 1;
//pixMap[k ++].code = GetCode(tpos + 1);
}
}
return Max;
}
int main()
{
int k;
int pix, pixNum;
while (cin >> width && width)
{
k = 0;
total = 0;
while(cin >> pix >> pixNum && pixNum)
{
mMap[k][0] = pix;
mMap[k ++][1] = pixNum;
total += pixNum;
}
int pairNum = k;
cout << width << endl;
int pos = 1;
k = 0;
for (int p = 0; p <= pairNum; ++ p)
{
int row = (pos - 1) / width;//the
int col = (pos - 1) % width;
for (int i = row - 1; i <= row + 1; ++ i)
{
for (int j = col - 1; j <= col + 1; ++ j)
{
int tpos = i * width + j;
if (i < 0 || j < 0 || j >= width || tpos >= total)
{
continue;
}
pixMap[k].pos = tpos + 1;
pixMap[k ++].code = GetCode(tpos + 1);
}
}
pos += mMap[p][1];
}
qsort(pixMap, k, sizeof(pixMap[0]), cmp);
struct Map tmp = pixMap[0];
for (int i = 0; i < k; ++ i)
{
if (tmp.code == pixMap[i].code)
{
continue;
}
cout << tmp.code << ' ' << pixMap[i].pos - tmp.pos << endl;
tmp = pixMap[i];
}
cout << tmp.code << ' ' << total - tmp.pos + 1 << endl;
cout << "0 0" << endl;
}
cout << 0 << endl;
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：poj 1009 这哪是模拟题啊？ 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)