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 |
为什么总是 Memory Limit Exceeded,请大牛指点#include<iostream> #include<vector> #include<utility> #include<algorithm> using namespace std; typedef pair<int,long long> Pair; vector<int> line; vector<Pair>linepress; int width; int Find(int i,int j){ int num1=i/width,num2=j/width,num3=i%width,num4=j%width; if(num2<num1-1||num2>num1+1) return -1; if(num4<num3-1||num4>num3+1) return -1; if(j>=0&&j<line.size()){ if(line[i]>line[j]) return line[i]-line[j]; else return line[j]-line[i]; } return -1; } int Deal(int i){ int arr[8]={Find(i,i-1),Find(i,i+1),Find(i,i-width),Find(i,i-width-1), Find(i,i-width+1),Find(i,i+width),Find(i,i+width-1),Find(i,i+width+1)}; sort(arr,arr+8); if(arr[7]!=-1) return arr[7]; else return line[i]; } int main(){ vector<long long> test; long long time; while(cin>>time) test.push_back(time); int count3=0; while(count3<test.size()){ width=test[count3]; count3++; int fir,count=0; long long sec; vector<int>lock; vector<long long>key; while(count3<test.size()){ fir=test[count3]; sec=test[count3+1]; count3=count3+2; if(fir==0&&sec==0) break; int num=4*width-1; if(sec>=num){ if(count%width==0) lock.push_back(count+width); else lock.push_back(count+2*width); long long sec2=sec; sec=sec%width+num+1; key.push_back(sec2-sec); } for(int i=0;i!=sec;i++){ line.push_back(fir); count++; } } int count2=0; for(int i=0;i!=line.size();++i){ int n=Deal(i); if(i>0&&linepress[linepress.size()-1].first==n) linepress[linepress.size()-1].second++; else linepress.push_back(Pair(n,1)); if((count2<lock.size())&&(i==lock[count2])){ linepress[linepress.size()-1].second+=key[count2]; count2++; } } cout<<width<<endl; for(vector<Pair>::iterator it=linepress.begin();it!=linepress.end();++it) cout<<(*it).first<<" "<<(*it).second<<endl; if(width!=0) cout<<0<<" "<<0<<endl; line.clear(); linepress.clear(); lock.clear(); key.clear(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator