poj 3262 比例贪心
来源:互联网 发布:瑜伽师地论 知乎 编辑:程序博客网 时间:2024/05/18 05:00
题意:
给时间,给消耗数。
每次带走一头牛,求最小花费。
解析:
亮GG刚开始讲贪心时候的那个英雄联盟比例贪心。
代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <queue>#include <map>#include <climits>#include <cassert>#define LL long long#define lson lo, mi, rt << 1#define rson mi + 1, hi, rt << 1 | 1using namespace std;const int maxn = 1e5 + 10;const int inf = 0x3f3f3f3f;const double eps = 1e-8;const double pi = acos(-1.0);const double ee = exp(1.0);struct COW{ int t, d;} cow[maxn];bool cmp(COW a, COW b){ return a.t * b.d < a.d * b.t;}int main(){#ifdef LOCAL freopen("in.txt", "r", stdin);#endif // LOCAL int n; while (~scanf("%d", &n)) { LL sumD = 0; for (int i = 0; i < n; i++) { scanf("%d%d", &cow[i].t, &cow[i].d); sumD = sumD + (LL)cow[i].d; } sort(cow, cow + n, cmp); LL ans = 0; for (int i = 0; i < n; i++) { sumD -= cow[i].d; ans = ans + 2 * sumD * (LL)cow[i].t; } printf("%lld\n", ans); } return 0;}
0 0
- poj 3262 比例贪心
- poj 3262 贪心
- poj 3262贪心
- POJ 3262 贪心
- poj 3262 贪心比率
- 贪心 POJ 3262
- POJ 3262 (贪心)
- poj 3262 贪心
- ZCC Loves Codefires 比例贪心 Codeforces
- POJ 3262 Protecting the Flowers 贪心
- poj 3262 Protecting the Flowers (贪心)
- poj 3262 Protecting the Flowers(贪心)
- poj 3262 Protecting the Flowers 【贪心】
- poj 3262 Protecting the Flowers(贪心)
- Protecting the Flowers - POJ 3262 贪心
- poj 3262 Protecting the Flowers(贪心)
- POJ 3262 Protecting the Flowers【贪心】
- POJ 3262 - Protecting the Flowers(贪心)
- java多线程学习-java.util.concurrent详解(四) BlockingQueue
- spring MVC 管理HttpClient---实现在java中直接向Controller发送请求
- linux diff命令详解
- Chromium浏览器之渲染引擎Blink
- mysql优化
- poj 3262 比例贪心
- Python sorted函数
- hdu 1201
- 快速幂模板 -->加法快速幂+乘法快速幂+矩阵快速幂
- error: server certificate verification failed 解决方案
- 全排列实现
- win7 安装 Delphi / C++ builder 无法打开"EditorLineEnds.ttr" dbExpress140.bpl
- dom4j解析soap型消息xml
- Digital Roots