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 |
贪心活动安排,求错或者bt数据……#include "stdio.h" #include <algorithm> using namespace std; #define M 50003 struct cow { int s,e,m; }; cow all1[M],all2[M],x; int cmp(cow a,cow b) { if(a.e!=b.e) return a.eb.e; else return a.s<b.s; } int cmp2(cow a,cow b) { return !cmp(a,b); } int main() { int k,n,c,i,j,n1,n2,total,p; //freopen("in.txt","r",stdin); while(scanf("%d%d%d",&k,&n,&c)>0) { n1=0;n2=0; for(i=0;i<k;i++) { scanf("%d%d%d",&x.s,&x.e,&x.m); if(x.s<x.e) {all1[n1]=x;n1++;} else {all2[n2]=x;n2++;} } sort(all1,all1+n1,cmp); sort(all2,all2+n2,cmp2); total=0; /*for(i=0;i<n1;i++) printf("%d %d %d\n",all1[i].s,all1[i].e,all1[i].m); printf("\n"); for(i=0;i<n2;i++) printf("%d %d %d\n",all2[i].s,all2[i].e,all2[i].m); printf("\n");*/ for(i=0;i<c;i++) { p=0; for(j=0;j<n1;j++) { if(all1[j].s>=p&&all1[j].m>0) { p=all1[j].e;all1[j].m--; total++; } } } for(i=0;i<c;i++) { p=n+1; for(j=0;j<n2;j++) { if(all2[j].s<=p&&all2[j].m>0) { p=all2[j].e;all2[j].m--; total++; } } } printf("%d\n",total); } return 0; } 大致思路是:来回分开考虑,每一个座位单独考虑。all1数组存放“去”的,all2数组存放“回”的。具体实现时,两个数组分别按目的地排序,all1中早到达目的地的排在前,同时到达目的地时,起点早的排在前。all2排序规则相反。对于每一个座位,看从头走到尾,最多能搭多少只牛,同时,若一群牛已被“前面”的座位载走,则不考虑这群牛。如此重复c次。total做统计。回来时,对all2进行相反的操作,统计total。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator