POJ3045+3258+2231
来源:互联网 发布:秦时明月动漫知乎 编辑:程序博客网 时间:2024/06/05 04:50
有点堕落
好几天没写了
先补上练习三的
A - Cow Acrobats
POJ - 3045The 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.
* Lines 2..N+1: Line i+1 describes cow i with two space-separated integers, W_i and S_i.
310 32 53 3
2
Put the cow with weight 10 on the bottom. She will carry the other two cows, so the risk of her collapsing is 2+3-3=2. The other cows have lower risk of collapsing.
风险就是当前牛头顶上牛的总体重减去他的力量
所有方案中,输出它风险最大的最小值
思路:猛一看以为是二分 其实不然 所有的牛都有份,体重重,力量大的在下面是必然的
根据题意,当前牛的风险值就等于头顶牛的总重量-改牛的力量,而且重的肯定在下面
所以就有了,求出全部重量,风险就成了 总重量-当前重量-当前力量 根据重量和力量的和排序即可
- Source Code
#include<iostream>#include<stdio.h>#include<algorithm>using namespace std;struct cow{ int w; int s; }a[50001];bool cmp(cow A,cow B){ return A.w+A.s>=B.w+B.s; }int main(){ int i,j; int n; while(cin>>n) { long long sum=0; for(i=0;i<n;i++) { scanf("%d %d",&a[i].w,&a[i].s); sum+=a[i].w; } sort(a,a+n,cmp); //for(i=0;i<n;i++) //cout<<a[i].w<<" "<<a[i].s<<endl; long long ans=-0x3f3f3f3f; for(i=0;i<n;i++) { sum-=a[i].w; ans=max(ans,sum-a[i].s); } cout<<ans<<endl; } return 0; }
B - River Hopscotch
POJ - 3258Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, Lunits away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distance Di from the start (0 < Di < L).
To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.
Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to M rocks (0 ≤ M ≤ N).
FJ wants to know exactly how much he can increase the shortest distance *before* he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks.
Lines 2.. N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.
25 5 2214112117
4
- Source Code
#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;int main(){ long long a[50001]; int i,j; long long l; int n,m; while(cin>>l>>n>>m) { //memset(a,0x3f3f3f,sizeof(a)); for(i=1;i<=n;i++) scanf("%lld",&a[i]); a[0]=0; a[n+1]=l; sort(a,a+n+2); //for(i=0;i<=n+1;i++) //cout<<a[i]<<endl; long long low=0,mid,high=l; while(low<high) { mid=(low+high)/2; int num=0; j=0; for(i=1;i<n+2;i++) { if(a[i]-a[j]<=mid) num++; else j=i; } if(num>m) high=mid; else low=mid+1; } cout<<low<<endl; } return 0; }
F - Moo Volume
POJ - 2231FJ's N cows (1 <= N <= 10,000) all graze at various locations on a long one-dimensional pasture. The cows are very chatty animals. Every pair of cows simultaneously carries on a conversation (so every cow is simultaneously MOOing at all of the N-1 other cows). When cow i MOOs at cow j, the volume of this MOO must be equal to the distance between i and j, in order for j to be able to hear the MOO at all. Please help FJ compute the total volume of sound being generated by all N*(N-1) simultaneous MOOing sessions.
* Lines 2..N+1: The location of each cow (in the range 0..1,000,000,000).
515324
40
There are five cows at locations 1, 5, 3, 2, and 4.
OUTPUT DETAILS:
Cow at 1 contributes 1+2+3+4=10, cow at 5 contributes 4+3+2+1=10, cow at 3 contributes 2+1+1+2=6, cow at 2 contributes 1+1+2+3=7, and cow at 4 contributes 3+2+1+1=7. The total volume is (10+10+6+7+7) = 40.
- Source Code
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;long long ans[100001],a[10001];int main(){ int i,j; int n; long long sum; while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); sum=0; for(i=0;i<n;i++) { scanf("%lld",&a[i]); } sort(a,a+n); for(i=0;i<n;i++) { ans[i]=ans[i-1]+(a[i]-a[i-1])*i; sum+=ans[i]; } cout<<2*sum<<endl; } return 0; }
- POJ3045+3258+2231
- poj3045
- poj3045
- poj3045
- POJ3045
- poj3045 贪心
- poj3045.cpp
- POJ3045(贪心)
- POJ3045 Cow Acrobats (贪心)
- [贪心]poj3045 Cow Acrobats
- POJ3045 Cow Acrobats(贪心)
- POJ3045 Cow Acrobats(贪心)
- POJ3045--Cow Acrobats
- 【poj3045】牛的杂技
- POJ3045-Cow Acrobats
- poj3045 牛的杂技
- POJ3045 Cow Acrobats
- POJ3045-Cow Acrobats
- java设计模式之单例模式
- IR21系列栅极驱动自举升压原理
- Redis提供的持久化机制(RDB和AOF)
- URL.createObjectURL和URL.revokeObjectURL
- HDU 6162 Ch's gift
- POJ3045+3258+2231
- STM32单片机—编码器测速
- Scala:fold,foldLeft和foldRight区别与联系
- JavaScript实现-句中单词首字母大写-Title Case a Sentence
- [题解] P2014 选课(树形DP+拓扑)
- xml解析
- QT之arcTo()函数详解
- Silver Cow Party POJ
- web app实现基站定位获取精确地理位置的一种简单方法