• cdoj第13th校赛初赛L


    http://acm.uestc.edu.cn/#/contest/show/54

    L - Lovely princess

    Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
     

    There are n jobs you need to complete. However, complete the ith job you capability must be no less than vi. If you have completed the ith job, your capability will increase ai.

    Then the question is coming, what is the minimum initial capability value if you are required to complete all of the n jobs.

    Note that there is no restriction on the order you complete them. That is to say, you can decide the order by your own.

    Input

    The first line contains a single integer n, which is the number of jobs you need to complete.

    Then each of the following n lines contains 2 integers vi and ai, which are described above.

    1≤n≤1000,0≤vi≤1000000,0≤ai≤1000

    Output

    Print the answer in one line.

    Sample input and output

    Sample InputSample Output
    1
    2 1
    2

    思路:运用贪心策略,对v排序。(之前一直tle,因为读错了题,以及v是消耗值。。。囧)

    官方题解:

    代码:

     1 #include <fstream>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <cstdio>
     5 #include <cstring>
     6 #include <cmath>
     7 #include <cstdlib>
     8 #include <vector>
     9 
    10 using namespace std;
    11 
    12 #define PI acos(-1.0)
    13 #define EPS 1e-10
    14 #define lll __int64
    15 #define ll long long
    16 #define INF 0x7fffffff
    17 
    18 const int N=1005;
    19 
    20 struct node{
    21     int v,a;
    22 }yu[N];
    23 int n,ans,cans;
    24 
    25 bool cmp(const node &r1,const node &r2){
    26     return r1.v<r2.v;
    27 }
    28 
    29 int main(){
    30     //freopen("D:\input.in","r",stdin);
    31     //freopen("D:\output.out","w",stdout);
    32     int t1,t2;
    33     scanf("%d",&n);
    34     for(int i=0;i<n;i++){
    35         scanf("%d %d",&yu[i].v,&yu[i].a);
    36     }
    37     sort(yu,yu+n,cmp);
    38     for(int i=0;i<n;i++){
    39         if(cans<yu[i].v){
    40             ans+=yu[i].v-cans;
    41             cans=yu[i].v;
    42         }
    43         cans+=yu[i].a;
    44     }
    45     printf("%d
    ",ans);
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    nginx 编译参数详解(运维不得不看)
    nginx安装(1) – ttlsa教程系列之nginx
    Nginx配置文件详细说明
    ubuntu下nginx的启停等常用命令
    Ubuntu 14.04 安装最新稳定版Nginx 1.6.0
    nginx启动、重启、关闭
    Ubuntu下基于Nginx实现Tomcat集群负载均衡
    在Ubuntu 14.04安装Nginx
    ubuntu完全卸载nginx
    ubuntu 下mysql中文乱码问题解决方案
  • 原文地址:https://www.cnblogs.com/jiu0821/p/4378856.html
Copyright © 2020-2023  润新知