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 |
c/c++ WA, gcc/g++ AC, 什么原因,程序见内!#include <stdio.h> #include <memory.h> #define MaxM 23 struct STATIONS { int st,en; int odr; }order[MaxM]; int cap; int n,m; int i,j; int peo[MaxM]; int earn,ans; int a[MaxM]; int opt[MaxM]; int GetData() { scanf("%d%d%d",&cap,&n,&m); if (cap==0) return 0; for (i=1;i<=m;i++) scanf("%d%d%d",&order[i].st,&order[i].en,&order[i].odr); opt[m]=order[m].odr*(order[m].en-order[m].st); for (i=m-1;i>=1;i--) { opt[i]=opt[i+1]+order[i].odr*(order[i].en-order[i].st); } return 1; } int Backward(int ix) { int jx; for (jx=order[ix].st;jx<order[ix].en;jx++) peo[jx]=peo[jx]-order[ix].odr; earn=earn-order[ix].odr*(order[ix].en-order[ix].st); return 0; } int Forward(int ix) { int jx; for (jx=order[ix].st;jx<order[ix].en;jx++) peo[jx]=peo[jx]+order[ix].odr; earn=earn+order[ix].odr*(order[ix].en-order[ix].st); return 0; } int Judge(int ix) { int jx; if (a[ix]) { if (ix<=m-1 && earn+order[ix].odr*(order[ix].en-order[ix].st)+opt[ix+1]<=ans) return 0; for (jx=order[ix].st;jx<order[ix].en;jx++) if (peo[jx]+order[ix].odr>cap) return 0; } else if (ix<=m-1 && earn+opt[ix+1]<=ans) return 0; return 1; } int main() { while (GetData()) { ans=0; memset(peo,0,sizeof(peo)); earn=0; i=1; a[i]=-1; while (i>0) { if (i>m) { if (earn>ans) ans=earn; i--; if (a[i]) Backward(i); } else { a[i]++; if (a[i]>1) { i--; if (a[i]) Backward(i); } else if (Judge(i)) { if (a[i]) Forward(i); i++; a[i]=-1; } } } printf("%d\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator