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 |
为什么会Runtime error? 实在查不出来,拜托帮忙检查检查!(附程序)#include<iostream.h> using namespace std; #define MAX 10001 struct node { int a,b; }product[MAX]; int compare(const void *p,const void *q) { return (*(node*)p).a>(*(node*)q).a?1:-1; } int main() { int n,i,j,deadline,maxValue,maxone,total; bool s[MAX]; while(scanf("%d",&n)!=EOF) { deadline=0; for(i=0;i<n;i++) { scanf("%d%d",&product[i].b,&product[i].a); if(deadline<product[i].a) deadline=product[i].a; s[i]=false; } // b[i]表示价值,a[i]表示期限 qsort(product,n,sizeof(node),compare); total=0; for(i=deadline;i>=1;i--) { maxValue=0; maxone=-1; j=n-1; while(product[j].a >=i && j>=0) { if(s[j]!=true && product[j].b>maxValue) {maxValue=product[j].b; maxone=j;} j--; } if(maxone!=-1) total+=product[maxone].b; s[maxone]=true; } printf("%d\n",total); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator