第二次 HDOJ 1003
AC代码:
#include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cstring> using namespace std; #define Max 1005 struct Hk { int deadline; int score; }hk[Max]; //作业结构体 int day_nonius[Max]; //做一个标记 bool compare(Hk a, Hk b) { if(a.score == b.score) return a.deadline < b.deadline ; else return a.score > b.score; } int main(void) { freopen("in.txt","r",stdin); int N; scanf("%d",&N); while(N--) { int n; scanf("%d",&n); for(int i = 1; i <= n; i++) //输入 scanf("%d",&hk[i].deadline); for(int i = 1; i <= n; i++) scanf("%d",&hk[i].score); memset(day_nonius,0,sizeof(day_nonius)); sort(hk + 1,hk + 1 + n,compare); //排序 int recuce_s = 0; //前者表示扣除的总分数 for(int i = 1; i <= n; i++) { int count = 0; for(int j = hk[i].deadline; j >= 1; j--) { if(day_nonius[j] == 0) { day_nonius[j] = 1; count = 1; break; } } if(!count) recuce_s += hk[i].score; } printf("%d\n",recuce_s); } fclose(stdin); system("pause"); return 0; }