sgu259 Printed PR 贪心
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 贪心的更多相关文章
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- uva.10020 Minimal coverage(贪心)
10020 Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose t ...
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...
- POJ 1456 Supermarket 区间问题并查集||贪心
F - Supermarket Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- 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 ...
- UVa 10020 - Minimal coverage(区间覆盖并贪心)
Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose the min ...
- codeforces 335A Banana(贪心)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Banana Piegirl is buying stickers for ...
- UVA 10020 Minimal coverage(贪心 + 区间覆盖问题)
Minimal coverage The Problem Given several segments of line (int the X axis) with coordinates [Li, ...
- LOJ 3059 「HNOI2019」序列——贪心与前后缀的思路+线段树上二分
题目:https://loj.ac/problem/3059 一段 A 选一个 B 的话, B 是这段 A 的平均值.因为 \( \sum (A_i-B)^2 = \sum A_i^2 - 2*B \ ...
随机推荐
- 【codevs2370】小机房的树 LCA 倍增
2370 小机房的树 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 小机房有棵焕狗种的树,树上有N个节点,节点标号为0 ...
- WebBrowers & HtmlViewers collection
WebBrowers & HtmlViewers collection 浏览: 加入我的收藏 楼主: THtmlViewerhttps://github.com/BerndGabriel/Ht ...
- [转][C/C++]函数名字修饰(Decorated Name)方式
1.C/C++函数修饰名: 对于我们的C/C++源程序而言,函数名只是函数的一小部分,函数还有调用方式(参数入栈方式).返回值类型.参数个数和各参数类型等信息,对于C++类成员函数,还有更多信息.这些 ...
- JAVA工作方式
public class Hellow { int eyes = 2; int ears = 2; int legs = 4; void run(){ //方法 System.out.println( ...
- Windows Server 2012 R2 设置
一.任务栏左下角启动服务器管理器,然后进行设置.1.登录不显示服务器管理器 2.本地服务器,看到右边的IE增强的安全配置,如图所示,关闭两项内容.这样就关闭了IE增强安全提示框. 3.“工具”菜单,启 ...
- SpringMvc中的反射
controller中的方法,是通过反射调用的 spring监控controller中的注解,当命令符合某个注解的时候,通过反射,找到这个注解对应的方法,然后调用,处理完成得到返回值,再根据这个返回值 ...
- iOS开发XCODE5 SVN配置 使用办法
第一次弄svn版本控制,折腾了好久一直都出错!无意间看到一篇文章!貌似解决了,很感谢“代码妖娆” 的详细流程(http://blog.sina.com.cn/s/blog_68661bd80101ph ...
- 【python】import 模块、包、第三方模块
xx.py文件,称为模块(module),把不同模块归整到一起的文件夹,叫做包(package) 不同包下的模块可以重名,但是都不能和系统内建模块重名 包里面一定要有个__init__.py文件,否则 ...
- Notification通知栏
Notification通知栏 首先实现的功能就是通知栏显示Notification,Notification是显示在系统的通知栏上面的,所以Notification 是属于进程之前的通讯.进程之间的 ...
- 使用开源工具MonoDevelop开发GTK#图形界面
转自:http://developer.51cto.com/art/201011/235040.htm Mono一直到现在的2.8已经完全可以胜任一些比较小的项目了,但相关的开发文档与教程一直比较匮乏 ...