HDOJ HDU 1789 Doing Homework again ACM 1789 IN HDU
Posted on 2010-08-04 12:03 MiYu 閱讀(742) 評論(0) 編輯 收藏 引用 所屬分類: ACM ( 貪心 )//MiYu原創(chuàng), 轉(zhuǎn)帖請注明 : 轉(zhuǎn)載自 ______________白白の屋
題目地址 :
http://acm.hdu.edu.cn/showproblem.php?pid=1789
一道很標準的貪心題
直接貼代碼:
題目地址 :
http://acm.hdu.edu.cn/showproblem.php?pid=1789
一道很標準的貪心題
直接貼代碼:
//MiYu原創(chuàng), 轉(zhuǎn)帖請注明 : 轉(zhuǎn)載自 ______________白白の屋
#include <iostream>
#include <algorithm>
using namespace std;

typedef struct Hm
{
int score;
int day;
}Hm;
bool cmp ( Hm a, Hm b )


{
if ( a.score != b.score )

{
return a.score > b.score ;
}
else

{
return a.day < b.day;
}
}
int main()


{
int T;
cin >> T;
while ( T -- )

{
int N;
cin >> N;
Hm *hm = new Hm[N];

int flag[1001] =
{0};
for ( int i = 0; i != N ; ++ i )

{
cin >> hm[i].day;
}
for ( int i = 0; i != N ; ++ i )

{
cin >> hm[i].score;
}
sort ( hm, hm + N, cmp );
int total = 0;
for ( int i = 0; i != N; ++ i )

{
int j;
for ( j = hm[i].day; j != 0; -- j )

{
if ( !flag[j] )

{
flag[j] = 1;
break;
}
}
if ( !j )

{
total += hm[i].score;
}
}
cout << total << endl;
delete [] hm;
}
return 0;
}






















































































