zoukankan      html  css  js  c++  java
  • whu Problem 1537

    题目链接:

    http://acm.whu.edu.cn/land/problem/detail?problem_id=1537

    Stones I

    Time Limit: 1000MS
    Memory Limit: 65536KB
    #### 问题描述 > Xiaoming took the flight MH370 on March 8, 2014 to China to take the ACM contest in WHU. Unfortunately, when the airplane crossing the ocean, a beam of mystical light suddenly lit up the sky and all the passengers with the airplane were transferred to another desert planet. > > When waking up, Xiaoming found himself lying on a planet with many precious stones. He found that: > > There are n precious stones lying on the planet, each of them has 2 positive values ai and bi. Each time Xiaoming can take the ith of the stones ,after that, all of the stones’ aj (including the stones Xiaoming has taken) will cut down bi units. > > Xiaoming could choose arbitrary number (zero is permitted) of the stones in any order. Thus, he wanted to maximize the sum of all the stones he has been chosen. Please help him. #### 输入 > The input consists of one or more test cases. > > First line of each test case consists of one integer n with 1 <= n <= 1000. > Then each of the following n lines contains two values ai and bi.( 1<= ai<=1000, 1<= bi<=1000) > Input is terminated by a value of zero (0) for n. #### 输出 > For each test case, output the maximum of the sum in one line. ####样例输入 > 1 > 100 100 > 3 > 2 1 > 3 1 > 4 1 > 0 ####样例输出 > 0 > 3 ## 题意 > 有n个石头,每个石头有价值ai,bi,你捡起第i个石头,所有的石头的价值都会减bi,问最后你能拿到的最大价值是多少。 ## 题解 > 你会发现对于第i个石头的贡献为ai - m * bi(m为你最后捡起的石头的贡献),直接枚举m再对ai - m * bi排个序。取前m大就可以了。

    代码

    #include<map>
    #include<set>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<ctime>
    #include<vector>
    #include<cstdio>
    #include<string>
    #include<bitset>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<functional>
    using namespace std;
    #define X first
    #define Y second
    #define mkp make_pair
    #define lson (o<<1)
    #define rson ((o<<1)|1)
    #define mid (l+(r-l)/2)
    #define sz() size()
    #define pb(v) push_back(v)
    #define all(o) (o).begin(),(o).end()
    #define clr(a,v) memset(a,v,sizeof(a))
    #define bug(a) cout<<#a<<" = "<<a<<endl
    #define rep(i,a,b) for(int i=a;i<(b);i++)
    #define scf scanf
    #define prf printf
    
    typedef long long LL;
    typedef vector<int> VI;
    typedef pair<int,int> PII;
    typedef vector<pair<int,int> > VPII;
    
    const int INF=0x3f3f3f3f;
    const LL INFL=0x3f3f3f3f3f3f3f3fLL;
    const double eps=1e-8;
    const double PI = acos(-1.0);
    
    //start----------------------------------------------------------------------
    
    const int maxn=1111;
    
    int a[maxn],b[maxn],c[maxn];
    int n;
    
    int main() {
        while(scf("%d",&n)==1&&n){
            rep(i,0,n){
                scf("%d%d",&a[i],&b[i]);
            }
            int ans=0;
            for(int m=1;m<=n;m++){
                rep(i,0,n){
                    c[i]=a[i]-m*b[i];
                }
                sort(c,c+n);
                int tmp=0;
                for(int i=0;i<m;i++){
                    tmp+=c[n-i-1];
                }
                ans=max(ans,tmp);
            }
            prf("%d
    ",ans);
        }
        return 0;
    }
    
    //end-----------------------------------------------------------------------
  • 相关阅读:
    洛谷——P2054 [AHOI2005]洗牌(扩展欧几里得,逆元)
    线性筛法(伪模板及。。。)
    洛谷——P3919 【模板】可持久化数组(可持久化线段树/平衡树)
    CF450B Jzzhu and Sequences(矩阵加速)
    洛谷——P1349 广义斐波那契数列(矩阵加速)
    P1269 信号放大器
    istio prometheus预警Prometheus AlertManager
    istio promethus收集不到数据
    KubeletNotReady runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
    centos7虚拟机设置静态ip
  • 原文地址:https://www.cnblogs.com/fenice/p/5852686.html
Copyright © 2011-2022 走看看