标签:
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <cstring> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <map> #define PI acos(-1.0) #define ms(a) memset(a,0,sizeof(a)) #define msp memset(mp,0,sizeof(mp)) #define msv memset(vis,0,sizeof(vis)) using namespace std; //#define LOCAL struct Node { int da;//日期 int gd;//分数 }t; bool date[1200]; vector<Node> v; int cmp(Node n1,Node n2) { if(n1.gd!=n2.gd)return n1.gd>n2.gd; return n1.da<n2.da; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL ios::sync_with_stdio(false); int N; while(cin>>N) { while(N--) { int n; cin>>n; v.clear(); ms(date); int ans=0; for(int i=0;i<n;i++) cin>>t.da,v.push_back(t); for(int i=0;i<n;i++) cin>>v[i].gd; sort(v.begin(),v.end(),cmp); for(int i=0,vsize=v.size();i<vsize;i++) { t=v[i]; for(int j=t.da;j>=0;j--) { if(j==0){ans+=t.gd;break;} if(date[j]==0){date[j]=1;break;} } } printf("%d\n",ans); } } return 0; }
HDU 1789 Doing Homework again(贪心)
标签:
原文地址:http://www.cnblogs.com/gpsx/p/5186751.html