POJ 3045 Cow Acrobats (想法题)

题目链接:POJ 3045 Cow Acrobats

题意:有n只牛叠罗汉,危险指数的计算是 该层牛以上的牛重量总和减去这层牛的强度,求使最大的危险指数中的最小值。

思路:根据w+s排序,最大的在最下面,道理很简单,危险指数: sum-(w+s),(sum该层牛以上的牛重量总和)。

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll __int64
using namespace std;
struct node
{
	ll w,s;
	ll sum;
};
struct node p[50010];

bool cmp(node a,node b)
{
	return a.sum<b.sum;
}
ll sum[50010];
int main()
{
	ll i;
	ll n;
	while(scanf("%I64d",&n)!=EOF)
	{
		memset(sum,0,sizeof sum);
		for(i=0;i<n;i++)
		{
			scanf("%I64d %I64d",&p[i].w,&p[i].s);
			p[i].sum=p[i].s+p[i].w;
		}
		sort(p,p+n,cmp);
		sum[0]=p[0].w;
		for(i=1;i<n;i++)
			sum[i]=sum[i-1]+p[i].w;
		ll max=sum[0]-p[0].s-p[0].w;
		for(i=1;i<n;i++)
		{
			ll temp=sum[i]-p[i].s-p[i].w;
			if(temp>max)
				max=temp;
		}
		printf("%I64d\n",max);
	}
return 0;
}
时间: 2024-08-07 06:51:00

POJ 3045 Cow Acrobats (想法题)的相关文章

poj 3045 Cow Acrobats(数学题)

题目链接:http://poj.org/problem?id=3045 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

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 ca

POJ 3045 Cow Acrobats

传送门:http://poj.org/problem?id=3104 题意: 烘干所有的衣服,在自然晾干每分钟可以减少1单位的水分,在烘干机里面每分钟减少k单位的水分, 一件衣服可以烘干一部分水分,也可以自然晒干一部分水分. 解题思路: 在代码中. 实现代码: #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int MAXN=100000; con

POJ 3045 Cow Acrobats (最大化最小值)

题目链接:click here~~ [题目大意] 给你n头牛叠罗汉.每头都有自己的重量w和力量s,承受的风险数rank就是该牛上面全部牛的总重量减去该牛自身的力量,题目要求设计一个方案使得全部牛里面风险最大的要最小. [解题思路]:依照w+s贪心放置,越大的(注意是w+s之和)越在以下.不难证明:假设最优放置时.相邻两头牛属性分别为w1,s1,w2,s2,第一头牛在第二头上面,sum为第一头牛上面的牛的体重之和.那么第一头牛风险:rank1=sum-s1;第二头牛风险:rank2=sum+w1-

POJ - 3045 Cow Acrobats 贪心

题目大意:有N头牛要叠罗汉,每头牛都有相应的重量和力量. 叠罗汉是有危险的,每头牛的危险系数为该牛上面的牛的重量的和减去该牛的力量 问如何安排这个叠罗汉顺序,使得危险系数最大的那头牛的危险系数最小 解题思路:最大值的最小值,用二分?二分当然也可以,但是有更简便的方法 假设第i头牛的重量为wi,力量为si,第j头牛的重量为wj,力量为sj,第i头牛上面的牛的重量和sum 先考虑第一种情况,第i头牛叠到第j头牛的上面 那么 a1 = sum -si, b1 = sum + wi -sj 考虑第二种情

POJ 1066 Treasure Hunt [想法题]

题目链接: http://poj.org/problem?id=1066 -------------------------------------------------------------------------------------------------------- 这题刚看后可能会去纠结如何建图后进行最短路 不过这样做不仅代码会复杂许多 还有可能出现些不好判断的部分 不过再多想一下我们可以发现如下性质 如果起点和终点位于某条障碍线段的两侧 那么这条线段有且仅有一次被穿过 所以只

POJ 3673 Cow Multiplication (水题)

题意:给你两个数,求所有的数位的积的和. 析:太水了,没的说,可以先输入边算,也可以最后再算,一样.. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <queue> #inclu

POJ3045 Cow Acrobats —— 思维证明

题目链接:http://poj.org/problem?id=3045 Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5713   Accepted: 2151 Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. The

poj 3270 Cow Sorting 置换群 简单题

假设初始状态为 a:2 3 1 5 4 6 则目标状态为 b:1 2 3 4 5 6且下标为初始状态中的3 1 2 4 5 6(a[3],a[1]...) 将置换群写成循环的形式 (2,3,1),(5,4),6就不用移动了. 移动方式2种 1:选循环内最小的数和其他len-1个数交换 2:选整个序列最小的数和循环内最小的数交换,转到1,再换回来. #include<cstdio> #include<queue> #include<algorithm> #include&