zoukankan      html  css  js  c++  java
  • POJ 3045 Cow Acrobats

    Description
    Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet prevent them from tightrope walking and swinging from the trapeze (and their last attempt at firing a cow out of a cannon met with a dismal failure). Thus, they have decided to practice performing acrobatic stunts.

    The cows aren't terribly creative and have only come up with one acrobatic stunt: standing on top of each other to form a vertical stack of some height. The cows are trying to figure out the order in which they should arrange themselves ithin this stack.

    Each of the N cows has an associated weight (1 <= W_i <= 10,000) and strength (1 <= S_i <= 1,000,000,000). The risk of a cow collapsing is equal to the combined weight of all cows on top of her (not including her own weight, of course) minus her strength (so that a stronger cow has a lower risk). Your task is to determine an ordering of the cows that minimizes the greatest risk of collapse for any of the cows.

    解题报告:
    各种乱搞+贪心WA一片,最后按w[i]+s[i]从大到小排序就莫名对了,后来仔细一想还是可靠的,假设A在B上面,那么 (rist_A=Sum-w_A-w_B-s_A) 并且交换A,B位置之后上面位置的risk都不变,但是下面的就会变成(Sum_B-w_A-s_A),所以贪心策略就是把 (w_i+s_i)最大的放在最下面,以此类推

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #define RG register
    #define il inline
    #define iter iterator
    #define Max(a,b) ((a)>(b)?(a):(b))
    #define Min(a,b) ((a)<(b)?(a):(b))
    using namespace std;
    typedef long long ll;
    const int N=5e4+5;
    int w[N],s[N],a[N];
    bool comp(int i,int j){
    	return w[i]+s[i]>w[j]+s[j];
    }
    void work()
    {
    	int n;ll tot=0;
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++){
    		scanf("%d%d",&w[i],&s[i]);
    		a[i]=i;tot+=w[i];
    	}
    	sort(a+1,a+n+1,comp);
    	int ans=-2e9;
    	for(int i=1;i<=n;i++){
    		ans=Max(ans,tot-w[a[i]]-s[a[i]]);
    		tot-=w[a[i]];
    	}
    	printf("%d
    ",ans);
    }
    
    int main()
    {
    	work();
    	return 0;
    }
    
  • 相关阅读:
    什么叫大数据,与云计算有何关系?
    基于TI 多核DSP 的大数据智能计算处理解决方案
    加固智能计算异构服务器
    Kintex7 XC7K325T 板卡五兄弟
    英伟达GPU 嵌入式开发平台
    NVIDIA Jetson™ TX1 Module
    Linux 高性能服务器编程——多线程编程
    Linux 高性能服务器编程——多进程编程
    Linux 高性能服务器编程——I/O复用的高级应用
    Linux 高性能服务器编程——I/O复用
  • 原文地址:https://www.cnblogs.com/Yuzao/p/7499863.html
Copyright © 2011-2022 走看看