一个类似国王游戏的贪心


话说要是先做了这个题,国王游戏之余懵逼这么久吗?

#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的更多相关文章

  1. bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...

  2. 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...

  3. 洛谷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. ...

  4. 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. ...

  5. USACO 保护花朵 Protecting the Flowers, 2007 Jan

    Description 约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的.他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草.可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园 ...

  6. USACO Protecting the Flowers

    洛谷 P2878 [USACO07JAN]保护花朵Protecting the Flowers 洛谷传送门 JDOJ 1009: 护花 JDOJ传送门 Description FJ出去砍木材去了,把N ...

  7. BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 448  So ...

  8. BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )

    考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...

  9. 1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 493  So ...

随机推荐

  1. ORACLE这门武功

    今天不是一个什么特别的日子,只是有些感触,特别是工作上的,所以就想记一变复杂的心情.有句话说:"人到中年不如狗",我不知道我现在的状况是不如狗,还是比狗好一点.但至少心情部复杂的. ...

  2. sqoop导出数据

    export是HDFS里的文件导出到RDBMS的工具,不能从hive.hbase导出数据,且HDFS文件只能是文本格式.如果要把hive表数据导出到RDBMS,可以先把hive表通过查询写入到一个临时 ...

  3. Indexing the World Wide Web: the Journey So Far阅读笔记

    文献文档用google搜索标题即可. term预处理:用空格切分,去除标点,去除撇号,归一化小写,去除变音符号,词干还原(?),去除停用词,挖掘词组. 索引选型工程最佳实践:term粒度.按doc分块 ...

  4. [转]win系统下nodejs安装及环境配置

    本文转自:http://www.cnblogs.com/linjiqin/p/3765390.html 第一步:下载安装文件 下载nodejs,官网:http://nodejs.org/downloa ...

  5. java多线程之守护线程与非守护线程

    在java线程中有两种线程,一种是用户线程,其余一种是守护线程. 守护线程具有特殊的含义,比如gc线程.当最后一个非守护线程执行完后,守护线程随着jvm一同结束工作. java中的守护线程需要将Dae ...

  6. Ubuntu18.10安装及优化

    最近机器学习很火,想来学习下,先来搭建一个学习平台. https://www.ubuntu.com 下载最新版本的系统,我这里是 18.10 桌面版. 然后进行分区,我这里在vm只创建了 80G的硬盘 ...

  7. Java基础入门 - Hello world

    JDK安装完成后,将一下代码写入文件HelloWorld.java中 // HelloWorld.java public class HelloWorld { public static void m ...

  8. Hibernate课程 初探一对多映射5-2 Eclipse添加数据库连接

    1 Eclipse新建java项目 2 Windows ==> show view == >other ==>Data source Explorer 3 左侧视图 database ...

  9. 从今天开始学习Swift -- Swift 初见 (转)

    原文地址:http://www.cocoachina.com/newbie/basic/2014/0604/8675.html   Swift系列文章由CocoaChina翻译小组翻译自苹果的官方文档 ...

  10. Redis入门--(二)Redis的安装

    1.建议安装在Linux服务器上来运行测试的