POJ --3045--Cow Acrobats(贪心模拟)】的更多相关文章

POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一层的风险值,找到其中的最大值 我一开始对sum-p[i].a-p[i].b从小到大排序,这样第一次取出的就是能使最下层的牛的风险最小的方案,在上移一层时,这一层的风险值   为sum-p[i].a-p[i].b-p[0].a,由于p[0].a是固定值,所以第二次直接取出的就是能使该层的牛的风险最小的…
一开始是往二分上去想的,如果risk是x,题目要求则可以转化为一个不等式,Si + x >= sigma Wj ,j表示安排在i号牛上面的牛的编号. 如果考虑最下面的牛那么就可以写成 Si + x  ≥ sum W - Wi,为了方便处理把i号牛的信息合并到一起 → Si + Wi + x ≥sum W. 二分x的时候,x是个常量,而从下面往上去安排牛的时候,下面的牛是没有影响决策的,可以看成把Wi去掉. 于是得到一个贪心的选法,把牛按照Si+Wi排序,从下面往上安排牛,可选择的牛应该满足Si+…
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…
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…
题目链接:click here~~ [题目大意] 给你n头牛叠罗汉.每头都有自己的重量w和力量s,承受的风险数rank就是该牛上面全部牛的总重量减去该牛自身的力量,题目要求设计一个方案使得全部牛里面风险最大的要最小. [解题思路]:依照w+s贪心放置,越大的(注意是w+s之和)越在以下.不难证明:假设最优放置时.相邻两头牛属性分别为w1,s1,w2,s2,第一头牛在第二头上面,sum为第一头牛上面的牛的体重之和.那么第一头牛风险:rank1=sum-s1;第二头牛风险:rank2=sum+w1-…
Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3686   Accepted: 1428 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 tig…
Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42701   Accepted: 10911 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges hi…
题目:http://poj.org/problem?id=3045 题意:每个牛都有一个wi和si,试将他们排序,每头牛的风险值等于前面所有牛的wj(j<i)之和-si,求风险值最大的牛的最小风险值 分析:这就是noip2012 T2的来源= =只不过这里是加,noip里是乘 不妨设所有牛都按最优顺序排好了,考虑相邻的两头牛i和i+1,如果交换他们的位置,那么对前面和后面的结果都无影响,只是他们两个的风险值变化了(变大了),于是我们可以得到这个时候i和i+1的关系 设w1+w2+...+wi-1…
传送门:http://poj.org/problem?id=1017 Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59106 Accepted: 20072 Description A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5…
题意:将n头牛叠起来,每头牛的力气 s体重 w  倒下的风险是身上的牛的体重的和减去s 求最稳的罗汉倒下去风险的最大值 思路: 将s+w最大的放在下面,从上往下看 解决问题的代码: #include<iostream> #include<cstdio> #include<cstring> #include <algorithm> using namespace std; int n; struct node { int w, s; bool operator…
有N (1 <= N <= 100,000)头奶牛在一个单人的超长跑道上慢跑,每头牛的起点位置都不同.由于是单人跑道,所有他们之间不能相互超越.当一头速度快的奶牛追上另外一头奶牛的时候,他必须降速成同等速度.我们把这些跑走同一个位置而且同等速度的牛看成一个小组. 请计算T (1 <= T <= 1,000,000,000)时间后,奶牛们将分为多少小组. #include<queue> #include<cstdio> #include<cstring&…
题目链接: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…
Cow Acrobats Descriptions 农夫的N只牛(1<=n<=50,000)决定练习特技表演. 特技表演如下:站在对方的头顶上,形成一个垂直的高度. 每头牛都有重量(1 <= W_i <= 10,000)和力量(1 <= S_i <= 1,000,000,000).奶牛崩溃的风险等同于她身上所有的奶牛的重量(当然不包括她自己)减去她的力量.你的任务是确定奶牛的顺序,从而使得所有牛的风险中最大的一个尽量小.Input第1行:一个整数N 第2 . .N+ 1…
Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status 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 th…
BUPT2017 wintertraining(16) #4 B POJ - 3045 题意 n(1 <= N <= 50,000) 个牛,重wi (1 <= W_i <= 10,000),力气si (1 <= S_i <= 1,000,000,000),堆成一个竖线,risk值为每只牛上面的w之和-它的si,使它的最大值最小,输出最小值. 题解 根据数据范围也可以知道要贪心. wi和si之和小的放上面.不要漏掉最top的牛的risk值. 证明:设i,j是相邻的两只牛,…
题目: poj3045 Cow Acrobats 解析: 贪心题,类似于国王游戏 考虑两个相邻的牛\(i\),\(j\) 设他们上面的牛的重量一共为\(sum\) 把\(i\)放在上面,危险值分别为\(x_1=sum-s_i\),$ x_2=sum+w_i-s_j$ 把\(j\)放在上面,危险值分别为\(x_3=sum-s_j\), \(x_4=sum+w_j-s_i\) 若把j放在上面更优,则有\(max(x_3,x_4)<max(x_1,x_2)\) 有四种情况 \(x_3<x_1\) \…
POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times A and B. Obvi…
Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4998   Accepted: 1892 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 tig…
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6253 Accepted: 2345 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 tightro…
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, 然后接下来的t秒需要的蜡烛都燃烧着,超过t秒,每减少一秒灭一支蜡烛,好!!! 详细解释:http://blog.csdn.net/kalilili/article/details/43412385 */ #include <cstdio> #include <algorithm> #i…
Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2302   Accepted: 912 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 tigh…
1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 601  Solved: 305[Submit][Status] 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 pre…
Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f…
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has…
POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最大值 分析:简单的动态规划,从上往下一层一层的考虑,对于每一行的最左边和最右边只有一种走法,只需要简单的相加, 对于中间的数要考虑是加上左上角的数还是加右上角的数,加上两者中的较大者 代码: #include<iostream> #include<cstdio> #include<…
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num[i].另一个限制条件,这个积木所在的位置不能高于limit[i],问能叠起的最大高度? 分析: 本题是一道多重背包问题, 只是每一个物品的选择不只要受该种物品的数量num[i]限制, 且该物品还受到limit[i]的限制. 这里有一个贪心的结论: 我们每次背包选取物品时都应该优先放置当前limit…
POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽默度看成体积,智商看成价值,那么就转换成求体积和价值都为正值的最大值的01背包了. 以 TS 作为体积,TF作为价值,在保证体积.价值非负的情况下,求解 sum,取其所有情况的最大值. 难点: 1)体积出现负数,将区间改变 [-100000, 100000] ---> [0, 200000]. (注…
题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的代码实在难懂啊~ */ /************************************************ * Author :Running_Time * Created Time :2015-8-16 14:29:49 * File Name :K.cpp **************…
POJ 2375 Cow Ski Area id=2375" target="_blank" style="">题目链接 题意:给定一个滑雪场,每一个点能向周围4个点高度小于等于这个点的点滑,如今要建电缆,使得随意两点都有路径互相可达,问最少须要几条电缆 思路:强连通缩点.每一个点就是一个点.能走的建边.缩点后找入度出度为0的个数的最大值就是答案.注意一開始就强连通了答案应该是0 代码: #include <cstdio> #includ…
Wilbur and Array Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he c…