zoukankan      html  css  js  c++  java
  • poj 1456

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #define N 10010
    #define inf 999999999
    int pre[N];
    struct node {
     int x,deadline;
    }map[N];
    int cmp(const void *a,const void *b) {
      return (*(struct node *)b).x -(*(struct node *)a).x;
    }
    int find(int x) {
     if(x!=pre[x])
      pre[x]=find(pre[x]);
     return pre[x];
    }
    int main(){
     int n,a,b,i,sum,max,m;
     while(scanf("%d",&n)!=EOF) {
      max=-1;
      for(i=0;i<n;i++) {
       scanf("%d%d",&a,&b);
           map[i].x=a;
        map[i].deadline=b;
        max=max<b?b:max;
      }
      qsort(map,n,sizeof(map[0]),cmp);
      for(i=1;i<=max;i++)
       pre[i]=i;
      sum=0;
      for(i=0;i<n;i++) {
                  m=find(map[i].deadline);
       if(m!=0) {
        sum+=map[i].x;
        pre[m]=m-1;
       }
      }
      printf("%d ",sum);
     }
     return 0;
    }
  • 相关阅读:
    ACM 一种排序
    ACM Binary String Matching
    ACM 括号配对问题
    ACM BUYING FEED
    ACM 喷水装置(二)
    ACM 会场安排问题
    ACM 推桌子
    ACM 心急的C小加
    ACM 田忌赛马
    ACM 疯牛
  • 原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410889.html
Copyright © 2011-2022 走看看