poj 3045 Cow Acrobats (贪心!!不是二分,)
生活随笔
收集整理的這篇文章主要介紹了
poj 3045 Cow Acrobats (贪心!!不是二分,)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Hint
樣例解釋: 把重量為10的牛放在底部。她將攜帶另外兩只牛,所以她的崩潰的風險是2 +3-3= 2。其他的奶牛有比她低的崩潰風險。
#include <iostream> #include <algorithm> #include <cstdio> using namespace std; #define MAX 50000 struct Cow {int weight, strength;bool operator<(const Cow& other)const{//return other.weight<weight;return other.strength+other.weight<strength+weight;} }cow[MAX]; int main() {int N;while(cin>>N){int total = 0;for (int i=0;i<N;++i){scanf("%d%d",&cow[i].weight,&cow[i].strength);total+= cow[i].weight;}sort(cow,cow+N);int risk = 0x80808080;for(int i=0; i<N;++i){total-=cow[i].weight; // 減去自己的重量risk=max(risk,total-cow[i].strength); // 計算risk}cout <<risk<<endl;}return 0; }
總結
以上是生活随笔為你收集整理的poj 3045 Cow Acrobats (贪心!!不是二分,)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: poj 3579 Median 中间值(
- 下一篇: poj2976Dropping test