一个类似国王游戏的贪心


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

#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. 实用的vue插件大汇总

    Vue是一个构建数据驱动的 web 界面的渐进式框架.Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件特别整理了常用的vue插件,来了个大汇总,方便查找使用,便于工作 ...

  2. call and apply

    apply()把参数打包成Array再传入: call()把参数按顺序传入. Math.max.apply(null, [3, 5, 4]); // 5 Math.max.call(null, 3, ...

  3. c++ primer 中讲的顶层const 和 底层 const 理解

    c++ primer 中讲的    顶层const 和 底层 const   以前没搞懂的顶层const和底层const,这次看了后感觉明白了. 首先,const是一个限定符,被它修饰的变量的值不能改 ...

  4. android Window(一)从setConetView说起

    Activity的源码 首先从setContentView这里调用的mWindow的 setConetView() private Window mWindow; public void setCon ...

  5. CentOS 7 Linux 卸载/安装 Mariadb MySQL mysql 5.7

    [root@localhost mysql]# ls mysql-community-client--.el7.x86_64.rpm mysql-community-embedded-compat-- ...

  6. Magnum DevStack安装

    local.conf文件 [[local|localrc]]DATABASE_PASSWORD=123456RABBIT_PASSWORD=123456SERVICE_TOKEN=123456SERV ...

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

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

  8. Spring boot-(1) Spring Boot快速开始

    本系列博客将学习并运用Spring Boot, 尽量会涉及到Spring Boot的方方面面,且会参考Spring Boot的官方文档,相关英文书籍,以及相关博客等知识,争取做到详尽易懂. 1. Sp ...

  9. 祝高二学弟学妹AK NOIp2018!!!!!!

         

  10. .NET 后台动态添加GridView列

    BoundField bfColumn1 = new BoundField(); bfColumn1.DataField = "zbcompanyname"; bfColumn1. ...