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<cstdio> #include<iostream> #include<algorithm> using namespace std; int t,n,k; struct walls{ int s,t,num; }wall[105]; int cnt[105]; bool cmp(walls a,walls b) { if(a.s == b.s) return a.t<b.t; return a.s<b.s; } int main() { int i,j,sun,ans,a,b; bool flag; scanf("%d",&t); while(t--) { sun = 0; memset(cnt,0,sizeof(cnt)); scanf("%d%d",&n,&k); for(i = 1;i<=n;i++) { scanf("%d%d%d%d",&a,&wall[i].num,&b,&wall[i].num); wall[i].s = a<b?a:b; wall[i].t = a>b?a:b; } sort(wall+1,wall+n+1,cmp); for(i = 1;i<=n;i++) { for(j = wall[i].s;j<=wall[i].t;j++) cnt[j]++; flag = false; for(j = wall[i].s;j<=wall[i].t;j++) { if(cnt[j]>k) { flag = true; break; } } if(flag) { int max = 0; for(int k = 1;k<=i;k++) if(wall[k].s<=j&&wall[k].t>=j) { if(wall[k].t-j>max) { max = wall[k].t-j; ans = k; } } for(int k = wall[ans].s;k<=wall[ans].t;k++) cnt[k]--; sun++; } } printf("%d\n",sun); } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator