链接:
http://poj.org/problem?id=1456
题目:
Description
Input
Output
Sample Input
4 50 2 10 1 20 2 30 1 7 20 1 2 1 10 3 100 2 8 2 5 20 50 10
Sample Output
80 185
#include
#include
#include
using namespace std;
const int N = 10005;
struct Node{
int px, dx;
friend bool operator<(const Node&a,const Node&b){
return a.dx>b.dx;
}
}arr[N];
priority_queue,less >q;
int n;
int main(){
while(~scanf("%d",&n)){
int maxTime=0;
for(int i=0; imaxTime) maxTime = arr[i].dx;
}
sort(arr,arr+n);
int ans = 0, pos=0;;
while(!q.empty()) q.pop();
for(int t=maxTime; t>=1; --t){
while(pos=t){
q.push(arr[pos++].px);
}
if(!q.empty()){
ans += q.top();
q.pop();
}
}
printf("%d\n", ans);
}
return 0;
}
#include
#include
#include
#include
using namespace std;
const int N = 10005;
struct Node{
int px, dx;
friend bool operator<(const Node&a,const Node&b){
return a.px>b.px;
}
}arr[N];
int n;
int main(){
while(~scanf("%d",&n)){
int maxTime=0;
for(int i=0; imaxTime) maxTime = arr[i].dx;
}
sort(arr,arr+n);
bool vis[N];
memset(vis, 0, sizeof(vis));
int ans = 0, pos=0;
for(int i=0; i=1; --j)if(!vis[j]){
ans += arr[i].px;
vis[j] = true;
break;
}
}
}
printf("%d\n", ans);
}
return 0;
}
#include
#include
#include
#include
using namespace std;
const int N = 10005;
struct Node{
int px, dx;
friend bool operator<(const Node&a,const Node&b){
return a.px>b.px;
}
}arr[N];
int f[N],rank[N],n;
inline void init(int n){
for(int i=0; i<=n; ++i)
f[i]=i, rank[i]=0;
}
int find(int x){
int i, j=x;
while(j!=f[j]) j=f[j];
while(x!=j){
i=f[x]; f[x]=j; x=i;
}
return j;
}
int main(){
while(~scanf("%d",&n)){
int maxTime=0;
for(int i=0; imaxTime) maxTime = arr[i].dx;
}
init(maxTime);
sort(arr,arr+n);
bool vis[N];
int ans = 0, pos=0;
for(int i=0; i0){
ans += arr[i].px;
f[d] = d-1;
}
}
printf("%d\n", ans);
}
return 0;
}
—— 生命的意义,在于赋予它意义。