zoj 3627(贪心)
思路:半夜了思路有点混乱wa了好几发。一开始坑定两个人距离为m才能获得最大的收益,所以我们就可以枚举单个端点,当距离达到m时在一同一个方向走这是我们只需要算一下剩下几秒,左右两边贪心去最大的即可。
代码如下:
1 /************************************************** 2 * Author : xiaohao Z 3 * Blog : http://www.cnblogs.com/shu-xiaohao/ 4 * Last modified : 2014-05-12 23:51 5 * Filename : poj_1741.cpp 6 * Description : 7 * ************************************************/ 8 9 #include <iostream> 10 #include <cstdio> 11 #include <cstring> 12 #include <cstdlib> 13 #include <cmath> 14 #include <algorithm> 15 #include <queue> 16 #include <stack> 17 #include <vector> 18 #include <set> 19 #include <map> 20 #define MP(a, b) make_pair(a, b) 21 #define PB(a) push_back(a) 22 23 using namespace std; 24 typedef long long ll; 25 typedef pair<int, int> pii; 26 typedef pair<unsigned int,unsigned int> puu; 27 typedef pair<int, double> pid; 28 typedef pair<ll, int> pli; 29 typedef pair<int, ll> pil; 30 31 const int INF = 0x3f3f3f3f; 32 const double eps = 1E-6; 33 const int LEN = 1000000+10; 34 ll num[LEN], sum[LEN]; 35 int n, p, m, t; 36 37 int Min(int a, int b, int c){ 38 return min(a, min(b, c)); 39 } 40 41 int Max(int a, int b, int c){ 42 return max(a, max(b, c)); 43 } 44 45 void J(int &pos){ 46 if(pos == n+1) pos = n; 47 else if(pos == 0) pos = 1; 48 } 49 50 int main() 51 { 52 // freopen("in.txt", "r", stdin); 53 54 while(scanf("%d%d", &n, &p)!=EOF){ 55 sum[0] = 0; 56 for(int i=1; i<=n; i++){ 57 scanf("%lld", &num[i]); 58 sum[i] = sum[i-1] + num[i]; 59 } 60 scanf("%d%d", &m, &t); 61 ll ans = 0; 62 for(int l=max(1, p-t); l<=p; l++){ 63 int r = Min(n, l+m, p+t); 64 int rest = t - max(p-l, r-p); 65 int a = max(1, l-rest); 66 int b = min(n, r+rest); 67 ans = max(ans, sum[b]-sum[l-1]); 68 ans = max(ans, sum[r]-sum[a-1]); 69 } 70 for(int r=min(n, p+t); r>=p; r--){ 71 int l = Max(1, r-m, p-t); 72 int rest = t - max(p-l, r-p); 73 int a = max(1, l-rest); 74 int b = min(n, r+rest); 75 ans = max(ans, sum[b]-sum[l-1]); 76 ans = max(ans, sum[r]-sum[a-1]); 77 } 78 printf("%lld\n", ans); 79 } 80 return 0; 81 }
View Code
转载于:https://www.cnblogs.com/shu-xiaohao/p/3724657.html
zoj 3627(贪心)相关推荐
- ZOJ 38727(贪心)
这道题真心坑.越想越远 想的飞起来了. 最后纠结起后缀表达式的定义来了. 题意: 就是给你一个串 , 让你用最少改动次数来实它变成一个合法的后缀表达式, 改动方式有两种, 一种是直接加入数字或者 ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- ZOJ 1025 Wooden Sticks(快排+贪心)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25 题目大意:机器运送n个木条,每个木条有一个长度和重量.运送第一根木 ...
- zoj 2709 Lottery 组合数,概率,贪心 (8-F)
题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2709 题解: 1 组合数的计算,用DP,速度又快又简洁. ...
- 【ZOJ - 2968 】Difference Game (贪心,思维模拟)
题干: Now you are going to play an interesting game. In this game, you are given two groups of distinc ...
- 【ZOJ - 3778】Talented Chef(贪心)
题干: As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same ti ...
- 【ZOJ - 3946】Highway Project(最短路子图,维护双权值,贪心,最小树形图)
题干: Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he ...
- 【ZOJ - 3963】Heap Partition (STLset,二叉树的性质,构造,贪心,思维)
题干: A sequence S = {s1, s2, ..., sn} is called heapable if there exists a binary tree Twith n nodes ...
- 【ZOJ - 3211】Dream City (01背包类问题,贪心背包)
题干: JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are n trees in the y ...
最新文章
- Android安全加密:非对称加密
- Flink从入门到精通100篇(六)-Flink 应用之 对Release 文档进行深度解读
- Input为number类型maxlength不好使,用js轻松解决
- python算法与数据结构-二分查找算法
- 学习3dmax的第二天
- Doug Cutting—访谈录
- Linux下下载JDK
- python json是什么_python json详解
- Python高级爬虫实战,JS解密咪咕音乐登录参数分析
- 15-自己写字符串库函数
- python 单反格式转格式_如何用单反斜杠转义字符串的特殊字符 - python
- 开源的长列表渲染库-Clusterize.js
- 问题:检测到远端X服务正在运行中(CVE-1999-0526)
- PPT如何设置背景色并应用到全局
- 我的世界java版和基岩版是什么意思_我的世界基岩版是什么意思
- incre在c语言,longest incresing sequence
- 控制测量的基本概念总结
- 计算机图形学实验二交互式绘制多边形
- 基于LabVIEW和USRP的文本传输
- 自主移动机器人常用的导航定位技术及原理
热门文章
- 查找只有一个字母不相同的单词
- 项目实战之组件化架构
- android phonegap插件开发方法 plugin
- memcached 缓存服务器
- Weblogic 9.2和10.3 改密码 一站完成
- [十一]基础数据类型之Character
- RBAC角色权限设计
- python2(中文编码问题):UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1...
- java操作protobuf
- linux学习笔记-rpm