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 ...
随机推荐
- 兼容最新firefox、chrome和IE的javascript图片预览实现代码
这篇文章主要介绍了兼容最新firefox.chrome和IE的javascript图片预览实现代码,测试了浏览器firefox6.firefox12.chrome 25.0.1364.172 m.IE ...
- EasyDarwin开源流媒体云平台中boost Base64编解码后与源长度不匹配的bug
本文转自EasyDarwin团队Alex的博客:http://blog.csdn.net/cai6811376 EasyDarwin云平台中部分协议使用了Base64编码昨晚报文通信的载体.比如在对摄 ...
- 获取一组radio按钮选中的值Value
1.效果 2.HTML代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind=" ...
- a completely rewritten architecture of Hadoop cluster
https://www.ibm.com/developerworks/library/bd-yarn-intro/
- java的多生产者多消费者例子
import java.util.concurrent.locks.*; public class Test9 { public static void main(String[] args) { / ...
- 20170313 ABAP程序未激活状态下保存或激活进入debug
自动进入断点,没有设置的.FUNCTION RS_NEW_PROGRAM_INDEX. https://archive.sap.com/discussions/message/14132983 解决办 ...
- linux 脚本统计代码行数
由于实际需求,需要统计开源产品的代码行数,so,以下命令统计*.c的行数. .h,.java .同理 find . -name *.c|xargs wc -l
- Java+Jsoup实现网页内容抓取
不知不觉毕业快一年了,工作逐渐趋于平淡,从一个对编程了解得很少甚至完全一窍不通的小小菜,终于成为了一枚小菜,总而言之,算是入了IT这一行.这大半年马马虎虎做了三个项目,有安卓项目,有Java Web项 ...
- html5--5-7 绘制圆/弧
html5--5-7 绘制圆/弧 学习要点 掌握arc() 方法创建圆弧/曲线(用于创建圆或部分圆) 矩形的绘制方法 rect(x,y,w,h)创建一个矩形 strokeRect(x,y,w,hx,y ...
- html5--3.15 textarea元素
html5--3.15 textarea元素 学习要点 掌握textarea元素的使用 textarea元素 用来建立多行输入文本框 元素标签中的内容将一文本框默认值的形式呈现 不仅可以用在表单中,也 ...