思路:

我们可以思考对于仅仅两个元素来说,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【贪心】的更多相关文章

  1. 51nod 1099 贪心/思维

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 1099 任务执行顺序 基准时间限制:1 秒 空间限制:13107 ...

  2. 51nod 1099:任务执行顺序 贪心

    1099 任务执行顺序 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  取消关注 有N个任务需要执行,第i个任务计算时占R[i]个空间,而后会释放一部分, ...

  3. 51nod 1099 任务执行顺序 (贪心算法)

    题目:传送门. 题意:中文题. 题解:r[i]-o[i]值大的先进行.反证法:如果大的后进行,会导致空间增大,所以一定大的是先进行. #include <iostream> #includ ...

  4. 51Nod 1099 任务执行顺序 (贪心)

    #include <iostream> #include <algorithm> using namespace std; +; struct node{ int r, q; ...

  5. 51nod 1163贪心

    用优先队列来贪心,是一个很好地想法.优先队列在很多时候可以维护最值,同时可以考虑到一些其他情况. http://www.51nod.com/onlineJudge/questionCode.html# ...

  6. 51NOD 1099 任务执行顺序

    来源:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 前天没睡好 昨天做题闷闷沉沉的 好多一眼题 都瞎做了 这题今 ...

  7. 51nod 1625 贪心/思维

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 1625 夹克爷发红包 基准时间限制:1 秒 空间限制:13107 ...

  8. 51nod 1428 贪心

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:13107 ...

  9. 51nod 1672 贪心/队列

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672 1672 区间交 基准时间限制:1 秒 空间限制:131072 K ...

随机推荐

  1. JavaScript根据Json数据来做的模糊查询功能

    类似于百度搜索框的模糊查找功能 需要有有已知数据,实现搜索框输入字符,然后Js进行匹配,然后可以通过鼠标点击显示的内容,把内容显示在搜索框中 当然了,正则只是很简单的字符匹配,不具备多么复杂的判断 & ...

  2. GreenPlum 安装方法详解

    一.安装环境准备 1.磁盘环境准备 磁盘分区典型配置如下: 文件系统 文件格式    大小  /        ext3   50GB,Linux系统的根目录,所有的目录都挂在这个目录下面,建议大小为 ...

  3. Java中的枚举类为何不能有public构造器

    声明:本博客为原创博客.未经同意.不得转载!原文链接为http://blog.csdn.net/bettarwang/article/details/27262809. 从Java 5開始有了枚举类, ...

  4. linux修改进程的名字

    1 修改linux进程名字的基本原理 linux进程以argv[0]作为进程的名字,因此只需要修改argv[0]处的字符串就修改了linux进程的名字. 2 直接修改argv[0]会导致的问题 如果名 ...

  5. wprintf、wcout无法输出中文的解决方案

    在C语言中,若wprintf无法输出中文,调用函数setlocale(int category, const char *locale)设置locale即可输出中文 此方法也可用于C++中 例: #i ...

  6. Jenkins安装部署及tomcat的入门介绍

    这里我们使用的方法是用servlet容器来部署jenkins,使用的是tomcat 下载下来tomcat,解压 bin目录下存放的一些启动关闭批处理文件 conf目录下放的一些配置文件,配置虚拟主机之 ...

  7. 6个基本screen命令

    screen -S  <name>    直接建立并进入<name>窗口 control+a    d    暂时退出窗口 (在会话内) screen -r <name& ...

  8. 【小程序】bindconfirm点击小键盘触发事件、focus自动获取焦点

    最近在写小程序,项目要求写一个搜索框,在进入页面时就触发input的事件,调出键盘,点小键上的搜索按钮 就触发搜索事件,分享一下. bindconfirm 是点击小键盘上的搜索按钮就触发要执行的方法 ...

  9. PHP编写网页BS结构计算器

    利用PHP和Html + javascript 编写一个简单的网页计算器程序,可以根据这种有趣的开发构架出更加有趣的网页.​1. [代码]PHP计算器    <html><head& ...

  10. codeforces B. Ilya and Queries 解题报告

    题目链接:http://codeforces.com/problemset/problem/313/B 题目意思:给出一个只有 "."  和  "#" 组成的序 ...