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 |
我的把讨论区里的数据测了一遍,都没问题,可就是WA,求助#include <iostream> #include <string.h> #include <algorithm> using namespace std; struct sa { int begin,end; } data[1000050]; int cmp(const sa&x,const sa&y) { if(x.begin==y.begin) return x.end>y.end; else return x.begin<y.begin; } int main() { sa tmp; int n,t; while(cin>>n>>t) { memset(data,0,sizeof(data)); // memset(tmp,0,sizeof(tmp)); for(int i=0; i<n; i++) cin>>data[i].begin>>data[i].end; sort(data,data+n,cmp); tmp=data[0]; if(tmp.begin!=1) { cout<<-1<<endl; //break; continue; } int maxn=-1,sum=1,flag=0,b=0; while(tmp.end<t&&flag<n) { for(int i=0; i<n; i++) { if(data[i].begin<=tmp.end+1&&data[i].end>=tmp.end+1&&tmp.end<t) { maxn=data[i].end; b=i; } // cout<<tmp.begin<<" "<<tmp.end<<endl; } tmp=data[b]; if(tmp.end<=t) { sum++; // cout<<sum<<endl; } flag++; // cout<<flag<<" "<<'a'<<endl; // cout<<tmp.begin<<" "<<tmp.end<<endl; } if(tmp.end!=t) { cout<<-1<<endl; } else { cout<<sum<<endl; } //for(int i=0;i<n;i++) // cout<<tmp.begin<<" "<<tmp.end<<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