• 51nod1163 最高的奖励


    1163 最高的奖励
    基准时间限制:1 秒 空间限制:131072 KB
    有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励。在结束时间之前完成该任务,就可以获得对应的奖励。完成每一个任务所需的时间都是1个单位时间。有时候完成所有任务是不可能的,因为时间上可能会有冲突,这需要你来取舍。求能够获得的最高奖励。
    Input
    第1行:一个数N,表示任务的数量(2 <= N <= 50000)
    第2 - N + 1行,每行2个数,中间用空格分隔,表示任务的最晚结束时间E[i]以及对应的奖励W[i]。(1 <= E[i] <= 10^9,1 <= W[i] <= 10^9)
    Output
    输出能够获得的最高奖励。
    Input示例
    7
    4 20
    2 60
    4 70
    3 40
    1 30
    4 50
    6 10
    Output示例
    230
    贪心
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<cstdlib>
     7 #include<vector>
     8 using namespace std;
     9 typedef long long ll;
    10 typedef long double ld;
    11 typedef pair<int,int> pr;
    12 const double pi=acos(-1);
    13 #define rep(i,a,n) for(int i=a;i<=n;i++)
    14 #define per(i,n,a) for(int i=n;i>=a;i--)
    15 #define Rep(i,u) for(int i=head[u];i;i=Next[i])
    16 #define clr(a) memset(a,0,sizeof(a))
    17 #define pb push_back
    18 #define mp make_pair
    19 #define fi first
    20 #define sc second
    21 #define pq priority_queue
    22 #define pqb priority_queue <int, vector<int>, less<int> >
    23 #define pqs priority_queue <int, vector<int>, greater<int> >
    24 #define vec vector
    25 ld eps=1e-9;
    26 ll pp=1000000007;
    27 ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;}
    28 ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;}
    29 void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
    30 //void add(int x,int y,int z){ v[++e]=y; next[e]=head[x]; head[x]=e; cost[e]=z; }
    31 int dx[5]={0,-1,1,0,0},dy[5]={0,0,0,-1,1};
    32 ll read(){ ll ans=0; char last=' ',ch=getchar();
    33 while(ch<'0' || ch>'9')last=ch,ch=getchar();
    34 while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
    35 if(last=='-')ans=-ans; return ans;
    36 }
    37 #include<queue>
    38 #include<vector>
    39 priority_queue<int,vector<int>,greater<int> > Q; 
    40 struct node{
    41     int i,v;
    42     friend bool operator < (node a,node b) 
    43     {
    44         return a.i<b.i;
    45     }
    46 }f[50005];
    47 int main(){
    48     int n=read(); long long ans=0,num=0;
    49     for (int i=1;i<=n;i++) f[i].i=read(),f[i].v=read();
    50     sort(f+1,f+n+1);
    51     for (int i=1;i<=n;i++){
    52         Q.push(f[i].v); num++;
    53         if (f[i].i<num) Q.pop(),num--;
    54     }
    55     while (!Q.empty()){
    56         ans+=Q.top();
    57         Q.pop(); 
    58     }
    59     printf("%lld",ans);
    60     return 0;
    61 } 
    View Code
  • 相关阅读:
    62. 不同路径
    63. 不同路径 II
    20220207
    春节前及春节期间学习目标、进度
    澳客竞彩分析
    2022段子手(最好的方式是抄过来,稍微改一点,比原作强就行)
    C#线程等待的几种方法
    MAUI学习笔记(五)MVVM模式
    WPF结合阿里巴巴矢量图标库使用ttf格式的图标字体
    MAUI学习笔记(三)视图绑定模型
  • 原文地址:https://www.cnblogs.com/SXia/p/7571352.html
Copyright © 2020-2023  润新知