P2878 [USACO07JAN]保护花朵Protecting the Flowers
一个类似国王游戏的贪心
话说要是先做了这个题,国王游戏之余懵逼这么久吗?
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
long long t;
long long d;
};
node data[101000];
bool compare(const node &a,const node &b)
{
return a.d*b.t>b.d*a.t;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",&data[i].t,&data[i].d);
sort(data+1,data+1+n,compare);
long long sum=0;
long long tim=0;
for(int i=1;i<=n;i++)
{
sum+=data[i].d*=tim;//牛都吓傻了
tim+=data[i].t*2;
}
printf("%lld",sum);
}
P2878 [USACO07JAN]保护花朵Protecting the Flowers的更多相关文章
- bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...
- 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...
- 洛谷P2878 [USACO07JAN]保护花朵Protecting the Flowers
题目描述 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. ...
- Luogu_2878_[USACO07JAN]保护花朵Protecting the Flowers
题目描述 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. ...
- USACO 保护花朵 Protecting the Flowers, 2007 Jan
Description 约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的.他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草.可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园 ...
- USACO Protecting the Flowers
洛谷 P2878 [USACO07JAN]保护花朵Protecting the Flowers 洛谷传送门 JDOJ 1009: 护花 JDOJ传送门 Description FJ出去砍木材去了,把N ...
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 448 So ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 493 So ...
随机推荐
- 自定义element-ui主题
自定义element主题颜色:主要参考这个文章https://blog.csdn.net/wangcuiling_123/article/details/78513245,再自己做了一遍成功.感谢. ...
- python 列表学习
一.创建一个列表(list)_使用逗号分隔不同的数据项,使用方括号括起来. list = [1,2,3,4,5,6,7] 与字符串的索引一样,列表索引从 0 开始,列表可以截取.组合. 二.访问列表中 ...
- Android NDK开发 JNI操作java构造方法,普通方法,静态方法(七)
Android NDK开发 JNI操作java普通.静态.构造方法 1.Jni实例化一个Java类的实例jobject 1.通过FindClas( ),获取Java类的的jclass 2.通过GetM ...
- notepad++查看Log
安装步骤:打开notepad++,插件→ Plugin Manager→ Show Plugin Manager→ Avaliable→ 等待插件列表刷新出来后,选中Android Logger插件→ ...
- Naive Operations
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315 学习博客:https://blog.csdn.net/SunMoonVocano/article ...
- 30段有用的javascript代码
1. 如何区分IE及非IE浏览器 if(!+[1,]){ console.log("这是IE浏览器"): } else{ console.log("这不是IE浏览器&qu ...
- python-常用模块整理
学习背景 最近需要进行文件夹数据的批量读取,里面会用到python里面的os模块.但是对os模块又不是很熟悉,里面的函数有哪些函数?有什么用?怎么用?英语不好的每次看官方文档也比较费力,所以就想着看看 ...
- 如何才能够写出优美的C代码呢?
转载自http://developer.51cto.com/art/201601/503802.htm 面向对象的语言更接近人的思维方式,而且在很大程度上降低了代码的复杂性,同时提高了代码的可读性和可 ...
- join() 和 sleep() 区别
来源于<Java多线程编程核心技术> 一.join() 作用 在很多情况,主线程创建并启动子线程,如果子线程中需要进行大量的耗时计算,主线程往往早于子线程结束.这时,如果主线程想等待子线程 ...
- Git GUI基本操作
一.Git GUI基本操作 1.版本库初始化 gitpractise文件夹就变成了Git可以管理的仓库,目录下多了一个.git文件夹,此目录是Git用于管理版本库的,不要擅自改动里面的文件,这样会破坏 ...