/*
poj 1009 Edge Detection
题意: 给出一副图要求刻画出另一幅图,刻画的图上每个像素值是取原图周围8个像素值与其像素值的最大差绝对值。
题解:模拟题
对于每一个变化点,一定是处于每个分界点所影响的位置,对于图来讲,我们就可以对分界点相邻及自身的9个格进行计算即可。
这题给出图的宽度,对于每对数据给出的pos,我们可以模拟出它相应的二维位置解决图的二维表示。
坑点: 光想着把有意义的pair作为分界点,最后结束也应该作为分界点,所以要把(0,0)这对也作为分界点。
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
pair<int,int> a[N];
struct asd //改变的点
{
int pos;
int val;
}ans[10*N];
int n;
int pos_sum;
int get_value(int pos)
{
int i = 0;
int now = 0;
while(now <= pos)
now += a[i++].second;
return a[i-1].first;
}
int cal(int pos)
{
int h = get_value(pos);
int x = pos/n;
int y = pos%n;
int mx = 0;
for(int j = x-1; j <= x+1; j++)
{
for(int k = y-1; k <= y+1; k++)
{
int pos_now = j*n+k;
if(!(j==x && k==y) && k < n && k >= 0 && j >= 0 && pos_now < pos_sum)
{
int f = get_value(pos_now);
mx = max(mx,abs(h-f));
}
}
}
return mx;
}
bool cmp(asd x,asd y)
{
return x.pos < y.pos;
}
int main()
{
while(cin >> n)
{
if(n == 0)
{
puts("0");
break;
}
int pair_num;
pos_sum = 0;
for(int i = 0; ; i++)
{
int v,f;
cin >> v >> f;
if(v==0 && f==0)
{
a[i] = make_pair(v,f);
pair_num = i;
break;
}
a[i] = make_pair(v,f);
pos_sum += a[i].second;
}
int pos = 0; //分界点的pos
int m = 0;
for(int i = 0; i <= pair_num; i++)
{
int x = pos/n;
int y = pos%n;
//cout << x << " " << y << endl;
for(int j = x-1; j <= x+1; j++)
{
for(int k = y-1; k <= y+1; k++)
{
int pos_now = j*n+k;
if(k < n && k >= 0 && j >= 0 && pos_now < pos_sum)
{
ans[m].pos = pos_now;
ans[m++].val = cal(pos_now);
}
}
}
pos += a[i].second;
}
sort(ans,ans+m,cmp);
cout << n << endl;
pos = 0;
for(int i = 1; i < m; i++)
{
if(ans[i].val == ans[i-1].val)
continue;
else
{
int x = pos/n;
int y = pos%n;
printf("%d %d\n",ans[i-1].val,ans[i].pos-pos);
pos = ans[i].pos;
}
}
int x = pos_sum - pos;
printf("%d %d\n",ans[m-1].val,x);
printf("0 0\n");
}
return 0;
}
/*
30
10 41
20 41
15 41
30 41
25 41
0 5
0 0
30
0 10
10 62
5 20
15 62
5 20
25 6
5 15
0 9
25 6
0 0
*/
【模拟】poj 1009 Edge Detection
最新推荐文章于 2017-10-30 21:30:22 发布