一个类似国王游戏的贪心


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

#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. VS 开发中觉得不错的几款插件

    1.C# Outline 2013  {}折叠 2.Indent Guides:为缩进添加竖直线 3.ResXManager:多语言资源文件编辑 4.C# Formatter:代码清理 5.Highl ...

  2. Mybatis学习笔记1 - Hello World

    1.pom.xml文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...

  3. window系统下SVN服务器和客户端的搭建和使用

    SVN服务器下载地址: http://subversion.apache.org/packages.html 这里我选用VisualSVN server 服务端和 TortoiseSVN客户端搭配使用 ...

  4. 关于C语言读取文件时候多读一行

    梗概:为什么C语言读取文件到结构体时为什么整天多读一行?一切都是[!feof(fp)]的错!!! while (!feof(fp)) { fgets(buffer, , fp); j++; } 像这样 ...

  5. js 页面按钮提交后 创建显示loading div 操作完成后 再隐藏或删除 进度div

    预期效果: 1.点击Save按钮,创建及显示loading div框 2.Save操作完成后,再删除loading 及弹出提示结果 <html> <head> </hea ...

  6. 安装weblogic步骤

    1 mkdir -p /home/geekc3t/weblogic 创建weblogic安装目录2 groupadd weblogic 创建weblogic组3 useradd -g weblogic ...

  7. WPF 正確理解ContentPresenter

    我們先由下圖來看類層次,可知ContentControl繼承Control,ContentPresenter繼承FrameworkElement(Control也繼承FrameworkElement) ...

  8. 操作符&流程控制

    运算符:算术运算符 赋值运算符  字符串运算符 递增(++)和递减(--)运算符 逻辑运算符 比较运算符 三元运算符         1.算术运算符           算术运算符,用于完成各种算术运 ...

  9. jq实例

    1.导航栏 <style type="text/css"> * {padding:0;margin:0;list-style:none;} img { width:11 ...

  10. dll托管于非托管

    托管的DLL组件可以在VS 直接添加引用,在使用using dll的文件命名空间就可以使用 非托管的DLL组件,只能通过using system.Runtime.InteropServices:引入 ...