51nod 1099【贪心】
思路:
我们可以思考对于仅仅两个元素来说,A,B;
先选A的话是会 A.b+B.a;
先选B的话是会 B.b+A.a;
所以哪个小哪个就放前面;
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <iostream>
using namespace std; typedef long long LL; const int N=1e5+10; struct asd{
LL a,b;
};
asd q[N]; bool cmp(asd x,asd y)
{
if(x.b+y.a<x.a+y.b)
return 1;
return 0;
} int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%lld%lld",&q[i].a,&q[i].b);
sort(q,q+n,cmp); LL p,ans,pre;
p=ans=0;
pre=0;
for(int i=0;i<n;i++)
{
p=p+q[i].a;
ans=max(ans,p);
p=p-q[i].a+q[i].b;
}
printf("%lld\n",ans);
return 0;
}
51nod 1099【贪心】的更多相关文章
- 51nod 1099 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 1099 任务执行顺序 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1099:任务执行顺序 贪心
1099 任务执行顺序 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 取消关注 有N个任务需要执行,第i个任务计算时占R[i]个空间,而后会释放一部分, ...
- 51nod 1099 任务执行顺序 (贪心算法)
题目:传送门. 题意:中文题. 题解:r[i]-o[i]值大的先进行.反证法:如果大的后进行,会导致空间增大,所以一定大的是先进行. #include <iostream> #includ ...
- 51Nod 1099 任务执行顺序 (贪心)
#include <iostream> #include <algorithm> using namespace std; +; struct node{ int r, q; ...
- 51nod 1163贪心
用优先队列来贪心,是一个很好地想法.优先队列在很多时候可以维护最值,同时可以考虑到一些其他情况. http://www.51nod.com/onlineJudge/questionCode.html# ...
- 51NOD 1099 任务执行顺序
来源:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 前天没睡好 昨天做题闷闷沉沉的 好多一眼题 都瞎做了 这题今 ...
- 51nod 1625 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 1625 夹克爷发红包 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1428 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1672 贪心/队列
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672 1672 区间交 基准时间限制:1 秒 空间限制:131072 K ...
随机推荐
- Mvc Autofac构造器注入
新建MVC项目,添加程序集引用 定义接口ILog public interface ILog { string Save(string message); } 类TxtLog实现接口ILog publ ...
- 生成ssh密钥
打开Git Bash,生成ssh密钥: ssh-keygen -t rsa -C "your_email@youremail.com"
- Android笔记之文本随滑块移动的SeekBar
效果图 FloatingTextSeekBar.java package com.bu_ish.blog; import android.content.Context; import android ...
- 阿里 JAVA 开发手册 学习 4 工程规约
应用分层 1.分层如下 1)开放接口层:可以直接封装Service接口暴露成RPC:通过web封装成http接口:网关控制层等. 2)终端显示层:各个端的模板渲染并执行显示层. 3)Web层:主要是度 ...
- 初学php html javascript后小总结
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/c3568/article/details/30474015 转载请注明出处:http://blog. ...
- ecshop属性排序
属性的排序有三个方式:sort_order, attr_price, goods_attr_id如果要修改的话,修改 includes/lib_goods.php文件的 get_goods_prope ...
- UITextField 对键盘一些常用属性 记录一下
autocapitalizationType 设置键盘自动大小写的属性 UITextAutocapitalizationTypeNone autocorrectionTy ...
- lAMP下新建维护站点全过程
由于window2003年7.15日微软对此不进行更新和支持,因此换了服务器系统由原来的windows2003直接升级到linux,关于LAMP的环境配置请查看我其他的相关博客,在这仅讲述一下LAMP ...
- android——array中设置选项
Android中,R.array是提取XML资源文件中String数组的方法.具体定义和提取的方法如下: 1)在R.array中定义字符数组 <?xml version="1.0&qu ...
- MFC窗口消息PostMessage和SendMessage
以前这些消息用得比较少,但是今天碰到了个事儿,我看非用消息不可. 事情是这样的,我在线程中需要刷新对话框上面的内容,但是每每执行到UpdateData时就出现了断言错误. 查了相关资料,发现这个可能是 ...