64,653
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include<map>
using namespace std;
map<int,int> input;
//int input[1002][2];
//int count;
bool insideImage(int x, int y,int w, int s)
{
if(x>=1&&y>=1&&x<=w&&(y-1)*w+x<=s) return true;
else return false;
}
int getPix(int x,int y, int w)
{
int t=(y-1)*w +x;
for(map<int,int>::iterator it=input.begin();it!=input.end();++it)
{
if(t<=it->first) return it->second;
}
//for(int i=1;i<count;i++)
//{
// if(t<=input[i][1]) return input[i][0];
//}
return 0;
}
int getVal(int x,int y, int w, int s)
{
int thisValue = getPix(x,y,w);
int temp = 0,max = 0;
for(int i=x-1;i<=x+1;i++)
{
for(int j=y-1;j<=y+1;j++)
{
if(insideImage(i,j,w,s))
{
temp = abs(thisValue-getPix(i,j,w));
if(temp>max) max = temp;
}
}
}
return max;
}
int main()
{
while(true)
{
map<int,int> output;
map<int,int>::iterator ot;
map<int,int>::iterator otNext;
int width,sum = 0;
//count = 1;
cin>>width;
if(width==0) break;
//memset(input,0x0,1002*2*sizeof(int));
input.clear();
//input[0][1]=0;
input[0] = 0;
while(true)
{
int val,len;
cin>>val>>len;
if(len==0) break;
sum += len;
//input[count][0]=val;
//input[count][1]=sum;
input[sum] = val;
//count++;
}
for(map<int,int>::iterator it=input.begin();it!=input.end();++it)
//for(int i =0;i<count;i++)
{
//int n=input[i][1] + 1;
int n = it->first + 1;
int x = 0,y = 0,dx = 0,dy = 0;
if(n%width == 0)
{
x=width;
y=n/width;
}
else
{
x=n%width;
y=n/width+1;
}
for(dx = x-1;dx<=x+1;dx++)
{
for(dy = y-1;dy<=y+1;dy++)
{
if(insideImage(dx,dy,width,sum))
output[(dy-1)*width+dx] = getVal(dx,dy,width,sum);
}
}
}
cout<<width<<endl;
ot = output.begin();
while(ot!=output.end())
{
otNext = ot;
otNext ++;
for(;otNext!=output.end()&&ot->second==otNext->second;++otNext);
if(otNext == output.end()) break;
else
{
cout<<ot->second<<" "<<otNext->first-ot->first<<endl;
ot = otNext;
}
}
cout<<ot->second<<" "<<sum-ot->first + 1<<endl;
cout<<"0 0"<<endl;
}
cout<<"0"<<endl;
return 0;
}