1009 Edge Detection


#include <iostream.h>
#include <math.h>
typedef int RLE[2];
int w,n,ct,t;
RLE r[2000];
RLE cur,pos;
bool Move(RLE a, RLE b, int offset) {
if ( a[0]<0 || a[0]>=n ) return false;
b[0] = a[0]; b[1] = a[1]+offset;
while ( b[1]>=r[b[0]][1] && b[0]<n ) {
b[1] -= r[b[0]][1];
b[0]++;
}
if ( b[0]>=n ) return false;
while ( b[1]<0 && b[0]>=0 ) {
b[0]--;
b[1] += r[b[0]][1];
}
if ( b[0]<0 ) return false;
return true;
}
void Advance() {
int temp = r[pos[0]][1]-pos[1]-w-1;
if ( pos[1]>w && temp>0 ) {
cur[1] += temp;
ct += temp;
pos[1] += temp;
}
temp = w-2 - ct%w;
int temp2 = r[pos[0]][1]-pos[1]-2;
if ( pos[1]==0 || pos[1]==1 || ct%w==0 ) temp2 = 0;
int temp3,temp4;
RLE trle;
if ( !Move(pos, trle, -w-2) ) temp3 = w;
else temp3 = r[trle[0]][1]-trle[1]-3;
if ( !Move(pos, trle, w-2) ) temp4 = w;
else temp4 = r[trle[0]][1]-trle[1]-3;
temp = (temp<temp2)?temp:temp2;
temp = (temp<temp3)?temp:temp3;
temp = (temp<temp4)?temp:temp4;
if ( temp>0 ) {
cur[1] += temp;
ct += temp;
pos[1] += temp;
}
int hehe=0;
Move(pos, trle, -w-1);
if ( ct>=w && ct%w>0 ) {
temp = abs(r[trle[0]][0] - r[pos[0]][0]);
if ( temp>hehe ) hehe = temp;
}
Move(pos, trle, -w);
if ( ct>=w ) {
temp = abs(r[trle[0]][0] - r[pos[0]][0]);
if ( temp>hehe ) hehe = temp;
}
Move(pos, trle, -w+1);
if ( ct>=w && ct%w!=w-1 ) {
temp = abs(r[trle[0]][0] - r[pos[0]][0]);
if ( temp>hehe ) hehe = temp;
}
Move(pos, trle, -1);
if ( ct%w>0 ) {
temp = abs(r[trle[0]][0] - r[pos[0]][0]);
if ( temp>hehe ) hehe = temp;
}
Move(pos, trle, 1);
if ( ct%w!=w-1 ) {
temp = abs(r[trle[0]][0] - r[pos[0]][0]);
if ( temp>hehe ) hehe = temp;
}
Move(pos, trle, w-1);
if ( ct<t-w && ct%w>0 ) {
temp = abs(r[trle[0]][0] - r[pos[0]][0]);
if ( temp>hehe ) hehe = temp;
}
Move(pos, trle, w);
if ( ct<t-w ) {
temp = abs(r[trle[0]][0] - r[pos[0]][0]);
if ( temp>hehe ) hehe = temp;
}
Move(pos, trle, w+1);
if ( ct<t-w && ct%w!=w-1 ) {
temp = abs(r[trle[0]][0] - r[pos[0]][0]);
if ( temp>hehe ) hehe = temp;
}
if ( cur[0] == -1 ) {
cur[0] = hehe;
cur[1] = 1;
} else if ( hehe == cur[0] ) cur[1]++;
else {
cout<<cur[0]<<' '<<cur[1]<<endl;
cur[0] = hehe;
cur[1] = 1;
}
pos[1]++; ct++;
if ( pos[1] == r[pos[0]][1] ) {pos[0]++; pos[1]=0;}
}
void Output() {
cur[0] = -1; cur[1] = -1;
pos[0] = 0; pos[1] = 0;
while ( true ) {
if ( pos[0] == n ) break;
Advance();
}
cout<<cur[0]<<' '<<cur[1]<<endl;
}
int main()
{
cin>>w;
while ( w>0 ) {
cout<<w<<endl;
n=0;
cin>>r[n][0]>>r[n][1];
t=r[n][1];ct=0;
while ( r[n][1]>0 ) {
n++;
cin>>r[n][0]>>r[n][1];
t += r[n][1];
}
Output();
cout<<"0 0"<<endl;
cin>>w;
}
cout<<w<<endl;

return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值