link:http://acm.sgu.ru/problem.php?contest=0&problem=259

思路就是贪心.

首先要读懂题目,输入的方式,把样例读懂.

第一,打印的总时间一定.需要做的就是送出的时间尽可能的重合,这样总时间就会更少.所以,送出时间长的要尽可能的先打印,按照送出时间从大到小排序就可以了.

 /*
* =====================================================================================
* Filename: 259.cpp
* Created: 06/08/2013 10:15:09
* Author: liuxueyang (lxy), 1459917536@qq.com
* Organization: Hunan University
*
* =====================================================================================
*/ /*
ID: zypz4571
LANG: C++
TASK: 259.cpp
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <list>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define LL long long
const double eps=1e-;
using namespace std;
struct Node{
int t, l;
bool operator < (const Node other) const {
if (l!=other.l) return l>other.l;
else return t<other.t;
}
}a[];
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
int n;
while (cin>>n) {
for (int i = ; i < n; ++i) cin>>a[i].t;
for (int i = ; i < n; ++i) cin>>a[i].l;
int ans=, sum=;
sort(a,a+n);
for (int i = ; i < n; ++i) {
sum += a[i].t;
ans = max(ans, sum+a[i].l);
}
cout<<ans<<endl;
}
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */

开始要读懂题目意思啊,读题认真.

sgu259 Printed PR    贪心的更多相关文章

  1. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  2. uva.10020 Minimal coverage(贪心)

    10020 Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose t ...

  3. [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)

    Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...

  4. POJ 1456 Supermarket 区间问题并查集||贪心

    F - Supermarket Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  5. Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心

    B. War of the Corporations 题目连接: http://www.codeforces.com/contest/625/problem/B Description A long ...

  6. UVa 10020 - Minimal coverage(区间覆盖并贪心)

    Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose the min ...

  7. codeforces 335A Banana(贪心)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud    Banana Piegirl is buying stickers for ...

  8. UVA 10020 Minimal coverage(贪心 + 区间覆盖问题)

     Minimal coverage  The Problem Given several segments of line (int the X axis) with coordinates [Li, ...

  9. LOJ 3059 「HNOI2019」序列——贪心与前后缀的思路+线段树上二分

    题目:https://loj.ac/problem/3059 一段 A 选一个 B 的话, B 是这段 A 的平均值.因为 \( \sum (A_i-B)^2 = \sum A_i^2 - 2*B \ ...

随机推荐

  1. xcode6 ios launchimage

    1.点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image" 2.右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以及低版本的ios系 ...

  2. Oracle常用的函数

    1.常用的函数分为五大类: 字符函数.数字和日期函数.数字函数.转换函数.混合函数 2.字符函数 字符函数主要用于修改字符列.这些函数接受字符输入,返回字符或数字值.Oracle 提供的一些字符函数如 ...

  3. initWithFrame 和 initWithCoder

    当我们所写的程序里没用用Nib文件(XIB)时,用代码控制视图内容,需要调用initWithFrame去初始化 - (id)initWithFrame:(CGRect)frame { if (self ...

  4. C++学习之静态成员

    一.静态数据成员 C++允许将类的数据成员定义为静态成员.静态数据成员是属于类的,整个类只有一个备份,相当于类的全局变量,能够被该类的所有对象共用. 1.静态成员的声明 在类数据成员的声明前加上关键字 ...

  5. 按Right-BICEP要求的任务二的测试

    测试方法:Right-BICEP 测试计划: 1.Right-结果是否正确? 2.B-是否所有的边界条件都是正确的? 3.P-是否满足性能要求? 4.是否有乘除法? 5.是否有括号? 6.是否有输出方 ...

  6. ios创建bundle的图片资源文件(转)

    在ios开发中为了方便管理资源文件,可以使用bundle的方式来进行管理,比如kkgridview里就是把所需的图片文件全部放在一个bundle来管理的 . 切记目前iOS中只允许使用bundle管理 ...

  7. struts调用的几种方法

    在Struts2中方法调用概括起来主要有三种形式 第一种方式:指定method属性 <action name="student" class="com.itmyho ...

  8. (转)mysql账号权限密码设置方法

    原文:http://www.greensoftcode.net/techntxt/2013410134247568042483 mysql账号权限密码设置方法 我的mysql安装在c:\mysql 一 ...

  9. Emacs常用命令

    1.离开Emacs 挂起Emacs C-z 退出Emacs C-x C-c 2.文件 打开文件 C-x C-f 保存文件 C-x C-s 保存所有的文件 C-x s 将一个文件的内容插入到当前buff ...

  10. Discuz 插件制作之后台常用函数详解

    目录 showsetting()表单显示 cpmsg()提示消息 showformheader()创建表单头 showformfooter()创建表单尾 showtableheader()创建表格头 ...