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 |
请问哪位高手能帮我找出问题来,或者几组错误数据也可以,谢谢啦![code] #include<iostream> #include<vector> #include<algorithm> using namespace std; struct node{ int st; int et; int pc; }; node ta[1000]; struct student{ vector<node> r; }; student stu[10000]; bool sorted[10000]; bool visit[10000]; bool cmp(node b,node c) { return b.st <c.st ; } int main() { int n,m,r,i,j,t,pc,stud,s,q,num; node temp; while(scanf("%d %d",&n,&m)){ if(m==0 && n==0) break; memset(visit,false,sizeof(visit)); memset(sorted,false,sizeof(sorted)); int task=0; scanf("%d",&r); for(i=0;i<r;i++){ scanf("%d%d%d%d",&t,&pc,&stud,&s); //push if(!visit[stud]){ visit[stud]=true; stu[stud].r.clear (); } if(s==1){ temp.pc =pc; temp.st =t; stu[stud].r.push_back (temp); } //define else { num=stu[stud].r .size (); for(j=num-1;j>=0;j--){ if(stu[stud].r [j].pc ==pc){ stu[stud].r [j].et =t; break; } } } } int stime,etime,sum,flag; scanf("%d",&q); for(i=0;i<q;i++){ sum=0; scanf("%d %d %d",&stime,&etime,&stud);//¿ªÊ¼Ê±¼ä£¬½áÊøʱ¼ä£¬Ñ§Éú if(stu[stud].r.size ()==0) {printf("0\n");continue;} if(!sorted[stud]){ sorted[stud]=true; sort(stu[stud].r.begin (),stu[stud].r .end (),cmp); } //body num=stu[stud].r.size(); //block int blocks=0; ta[0].st=stu[stud].r [0].st ; ta[0].et=stu[stud].r [0].et ; for(j=1;j<num;j++){ if(stu[stud].r [j].st >ta[blocks].et) { blocks++; ta[blocks].st=stu[stud].r [j].st ; ta[blocks].et=stu[stud].r [j].et ; } else if(stu[stud].r [j].et >ta[blocks].et) ta[blocks].et=stu[stud].r [j].et; } //compute for(j=0;j<=blocks;j++){ if(ta[j].st <=stime && stime<ta[j].et && ta[j].et<etime) sum+=ta[j].et-stime; else if(stime<=ta[j].st &&ta[j].et<=etime) sum+=ta[j].et-ta[j].st; else if(stime < ta[j].st && ta[j].st <=etime && etime<ta[j].et) sum+=etime-ta[j].st; else if(ta[j].st <=stime && ta[j].et >=etime) sum+=etime-stime; else if(ta[j].st>=etime) break; } printf("%d\n",sum); } } return 0; } [/code] Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator