POJ 1144 Network
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5098 Accepted Submission(s): 3004
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
0 3 5
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int visi[1005]; struct node { int time; int score; }nod[1005]; int cmp(node a,node b) { if(a.score>b.score) return 1; if(a.score==b.score&&a.time>b.time) return 1; return 0; } int main() { int tes,n; cin>>tes; int i,j; int res; while(tes--) { res=0; cin>>n; for(i=0;i<n;i++) scanf("%d",&nod[i].time); for(i=0;i<n;i++) scanf("%d",&nod[i].score); sort(nod,nod+n,cmp); memset(visi,0,sizeof(visi)); for(i=0;i<n;i++) { int flag=0; j=nod[i].time; while(j) { if(!visi[j]) { visi[j]=1; flag=1; break; } j--; } if(!flag) res+=nod[i].score; } cout<<res<<endl; } return 0; } /* 3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4 */
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。