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 |
为什么还错? 大家试一下#include <iostream> using namespace std; #define MAX 1000 short intensity[MAX]; int pos[MAX]; short myself; void edge(int, int); short getInt(int x, int y, int currX, int currY); short maxdiff8(short self, short a, short b, short c, short d, short e, short f, short g, short h); short max(short a, short b); short diff(short a, short b); short abs(short a); int main(){ int rows, cols; int cells=0, value=0, quantity=0; int counter=0; cin >> cols; while (cols!=0){ cin >> value >> quantity; while(value!=0 && quantity!=0){ cells += quantity; intensity[counter]=value; pos[counter] = cells; counter++; cin >> value >> quantity; } cout <<cols <<"\n"; rows=cells/cols; edge(cols, rows); cout<<"0 0" <<"\n"; cells=0; counter=0; cin >> cols; } cout << "0"; return 0; } void edge( int x, int y){ int i,j; short temp; int currCells=0, currValue=-1; int currPos=0; int cells = x*y; int n=0; int done=0; int curr; int jumpPos; for (j=0; j<y; j++){ for(i=0; i<x; i++){ /*some skipping needed*/ curr=i+j*x; if(done==0 && currCells>2*x){ for(n=0; n<MAX; n++){ if(curr<pos[n]){ if(pos[n]-currCells>2*x){ done=1; jumpPos = pos[n]-2*x-1; currCells+=(jumpPos-curr); i=jumpPos%x; j=jumpPos/x; break; } } } } myself=getInt(x,y,i,j); temp=maxdiff8( myself, getInt(x, y, i-1, j-1), getInt(x, y, i, j-1), getInt(x, y, i+1, j-1), getInt(x, y, i-1, j), getInt(x, y, i+1, j), getInt(x, y, i-1, j+1), getInt(x, y, i, j+1), getInt(x, y, i+1, j+1)); if(temp==currValue && (i+1)*(j+1)!=cells){ currValue=temp; currCells++; }else{ if((i+j)!=0) { if((i+1)*(j+1)==cells){ cout << currValue << " " << currCells+1 <<"\n"; }else{ cout << currValue << " " << currCells <<"\n"; } } currValue=temp; currCells=1; done=0; } } } return; } short getInt(int x, int y, int currX, int currY){ int res=currX+x*currY; if( res < 0 || res>x*y || currX<0 || currX>=x || currY<0 || currY>=y ){// = because currX is index x is length return myself; }else{ //para okay, do nothing } int i; for(i=0; i<MAX; i++){ if(res<pos[i]){ return intensity[i]; } } return -1; } short maxdiff8(short self, short a, short b, short c, short d, short e, short f, short g, short h){ short k=max( max( max(diff(self, a), diff(self, b)), max(diff(self, c), diff(self, d)) ), max( max(diff(self, e), diff(self, f)), max(diff(self, g), diff(self, h)) ) ); return k; } short max(short a, short b){ if (a>b){ return a; }else{ return b; } } short diff(short a, short b){ return abs(a-b); } short abs(short a){ if(a<0){ return -a; }else{ return a; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator