| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
总是runtime error,鸭梨好大呀,崩溃了。。。#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
struct Node{
int originalValue;
int x,y;
int length;
}node[100];
int numInput[100][2];
int countPot[100];
int column,line;
int xP[8]={-1,-1,-1,0,0,1,1,1};
int yP[8]={-1,0,1,-1,1,-1,0,1};
int compare(const void *n1,const void *n2){
if(((Node*)n1)->length<((Node*)n2)->length)
return -1;
else
return 1;
}
bool isImage(int x,int y){
return (x>=0&&x<line)&&(y>=0&&y<column);
}
int isPot(int l){
int i;
for(i=0;l>=countPot[i];++i)
if(l==countPot[i])
return 0;
i=(i-1)/2;
return numInput[i][0];
}
int findValue(int l){
int i;
for(i=0;l>=countPot[i];++i)
;
i=(i-1)/2;
return numInput[i][0];
}
int maxAbs(int number,int length){
int max=0;
for(int i=0;i<8;++i)
if(isImage(length/column+xP[i],length%column+yP[i])){
int num=findValue(length+xP[i]*column+yP[i]);
if((num=abs(num-number))>max)
max=num;
}
return max;
}
void newValue(){
int result[100][2]={0};
int resultcount=0;
result[resultcount][0]=maxAbs(node[0].originalValue,node[0].length);
result[resultcount][1]=1;
int temp0(result[resultcount][0]),temp1(0);
for(int i=1,num=0;node[i].length!=-1;++i){
num=node[i].length-node[i-1].length-1;
if(num==-1)
continue;
if(num>0){
temp1=maxAbs(findValue(node[i-1].length+1),node[i-1].length+1);
if(temp1!=temp0)
result[++resultcount][0]=temp1;
temp0=temp1;
result[resultcount][1]+=num;
}
temp1=maxAbs(node[i].originalValue,node[i].length);
if(temp1!=temp0)
result[++resultcount][0]=temp1;
temp0=temp1;
result[resultcount][1]+=1;
}
for(int i=0;i<=resultcount;++i)
cout<<result[i][0]<<" "<<result[i][1]<<endl;
cout<<0<<" "<<0<<endl;
}
void dealWith(){
int i,j,k;
for(i=0,j=0,k=0;;++i){
if(numInput[i][0]==0&&numInput[i][1]==0)
break;
int n=2;
while(n--){
node[j].originalValue=numInput[i][0];
node[j].x=countPot[k]/column;
node[j].y=countPot[k]%column;
node[j].length=countPot[k++];
int value,temp=j;
if(isImage(node[temp].x-1,node[temp].y)&&(value=isPot((node[temp].x-1)*column+node[temp].y))!=0){
node[++j].x=node[temp].x-1;
node[j].y=node[temp].y;
node[j].length=node[j].x*column+node[j].y;
node[j].originalValue=value;
}
if(isImage(node[temp].x+1,node[temp].y)&&(value=isPot((node[temp].x+1)*column+node[temp].y))!=0){
node[++j].x=node[temp].x+1;
node[j].y=node[temp].y;
node[j].length=node[j].x*column+node[j].y;
node[j].originalValue=value;
}
++j;
}
}
qsort(node,j,sizeof(Node),compare);
node[j].length=-1;
newValue();
}
int main(){
int col[50]={0},c=0;
while(1){
cin>>column;
if(column==0)
break;
cout<<column<<endl;
//col[c++]=column;
for(int j=0,i=0,count=0;;++j){
cin>>numInput[j][0]>>numInput[j][1];
if(i==0)
countPot[i++]=0;
else
countPot[i++]=countPot[i-1]+1;
countPot[i++]=countPot[i-1]+numInput[j][1]-1;
count+=numInput[j][1];
if(numInput[j][0]==0&&numInput[j][1]==0){
line=count/column;
break;
}
}
dealWith();
}
cout<<0<<endl;
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator