POJ 3258 River Hopscotch

题目链接:https://vjudge.net/problem/POJ-3258

题目大意

  给定数轴上一个起点 0,终点 L,以及中间 N 个不同的点,现准备删除中间 N 个点中的 M 个,使得剩下来的点(包括起点和终点),相邻两点间距的最小值最大,求这个值。

分析

二分最短距离即可。

代码如下

  1 #include <cmath>
  2 #include <ctime>
  3 #include <iostream>
  4 #include <string>
  5 #include <vector>
  6 #include <cstdio>
  7 #include <cstdlib>
  8 #include <cstring>
  9 #include <queue>
 10 #include <map>
 11 #include <set>
 12 #include <algorithm>
 13 #include <cctype>
 14 #include <stack>
 15 #include <deque>
 16 #include <list>
 17 #include <sstream>
 18 #include <cassert>
 19 using namespace std;
 20  
 21 #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 22 #define Rep(i,n) for (int i = 0; i < (n); ++i)
 23 #define For(i,s,t) for (int i = (s); i <= (t); ++i)
 24 #define rFor(i,t,s) for (int i = (t); i >= (s); --i)
 25 #define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
 26 #define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
 27 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
 28 #define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i)
 29  
 30 #define pr(x) cout << #x << " = " << x << "  "
 31 #define prln(x) cout << #x << " = " << x << endl
 32  
 33 #define LOWBIT(x) ((x)&(-x))
 34  
 35 #define ALL(x) x.begin(),x.end()
 36 #define INS(x) inserter(x,x.begin())
 37 #define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
 38 #define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // 删去 x 中所有 c 
 39 #define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
 40 #define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper);
 41  
 42 #define ms0(a) memset(a,0,sizeof(a))
 43 #define msI(a) memset(a,inf,sizeof(a))
 44 #define msM(a) memset(a,-1,sizeof(a))
 45 
 46 #define MP make_pair
 47 #define PB push_back
 48 #define ft first
 49 #define sd second
 50  
 51 template<typename T1, typename T2>
 52 istream &operator>>(istream &in, pair<T1, T2> &p) {
 53     in >> p.first >> p.second;
 54     return in;
 55 }
 56  
 57 template<typename T>
 58 istream &operator>>(istream &in, vector<T> &v) {
 59     for (auto &x: v)
 60         in >> x;
 61     return in;
 62 }
 63  
 64 template<typename T1, typename T2>
 65 ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
 66     out << "[" << p.first << ", " << p.second << "]" << "\n";
 67     return out;
 68 }
 69 
 70 inline int gc(){
 71     static const int BUF = 1e7;
 72     static char buf[BUF], *bg = buf + BUF, *ed = bg;
 73     
 74     if(bg == ed) fread(bg = buf, 1, BUF, stdin);
 75     return *bg++;
 76 } 
 77 
 78 inline int ri(){
 79     int x = 0, f = 1, c = gc();
 80     for(; c<48||c>57; f = c=='-'?-1:f, c=gc());
 81     for(; c>47&&c<58; x = x*10 + c - 48, c=gc());
 82     return x*f;
 83 }
 84 
 85 template<class T>
 86 inline string toString(T x) {
 87     ostringstream sout;
 88     sout << x;
 89     return sout.str();
 90 }
 91 
 92 inline int toInt(string s) {
 93     int v;
 94     istringstream sin(s);
 95     sin >> v;
 96     return v;
 97 }
 98 
 99 //min <= aim <= max
100 template<typename T>
101 inline bool BETWEEN(const T aim, const T min, const T max) {
102     return min <= aim && aim <= max;
103 }
104  
105 typedef long long LL;
106 typedef unsigned long long uLL;
107 typedef pair< double, double > PDD;
108 typedef pair< int, int > PII;
109 typedef pair< int, PII > PIPII;
110 typedef pair< string, int > PSI;
111 typedef pair< int, PSI > PIPSI;
112 typedef set< int > SI;
113 typedef set< PII > SPII;
114 typedef vector< int > VI;
115 typedef vector< double > VD;
116 typedef vector< VI > VVI;
117 typedef vector< SI > VSI;
118 typedef vector< PII > VPII;
119 typedef map< int, int > MII;
120 typedef map< LL, int > MLLI;
121 typedef map< int, string > MIS;
122 typedef map< int, PII > MIPII;
123 typedef map< PII, int > MPIII;
124 typedef map< string, int > MSI;
125 typedef map< string, string > MSS;
126 typedef map< PII, string > MPIIS;
127 typedef map< PII, PII > MPIIPII;
128 typedef multimap< int, int > MMII;
129 typedef multimap< string, int > MMSI;
130 //typedef unordered_map< int, int > uMII;
131 typedef pair< LL, LL > PLL;
132 typedef vector< LL > VL;
133 typedef vector< VL > VVL;
134 typedef priority_queue< int > PQIMax;
135 typedef priority_queue< int, VI, greater< int > > PQIMin;
136 const double EPS = 1e-8;
137 const LL inf = 0x3fffffff;
138 const LL infLL = 0x3fffffffffffffffLL;
139 const LL mod = 1e9 + 7;
140 const int maxN = 1e5 + 7;
141 const LL ONE = 1;
142 const LL evenBits = 0xaaaaaaaaaaaaaaaa;
143 const LL oddBits = 0x5555555555555555;
144 
145 int L, N, M;
146 int dis[maxN >> 1], l, r;
147 
148 int main(){
149     //freopen("MyOutput.txt","w",stdout);
150     //freopen("input.txt","r",stdin);
151     //INIT();
152     while(~scanf("%d %d %d", &L, &N, &M)) {
153         dis[0] = 0;
154         For(i, 1, N) scanf("%d", &dis[i]);
155         dis[++N] = L;
156         sort(dis, dis + N + 1);
157         l = dis[1];
158         r = L;
159         Rep(i, N) {
160             dis[i] = dis[i + 1] - dis[i];
161             l = min(l, dis[i]);
162         }
163         
164         while(l < r) {
165             int mid = (l + r) >> 1, cnt = 0, sum = 0;
166             
167             Rep(i, N) {
168                 sum += dis[i]; 
169                 if(sum > mid) sum = 0; // 这里看的是 mid + 1 
170                 else ++cnt;
171             }
172             
173             if(cnt > M) r = mid;
174             else l = mid + 1;
175         }
176         
177         printf("%d\n", l);
178     }
179     return 0;
180 }
181 
182 /*
183 16 7 5
184 2 4 6 8 10 12 14
185 16 0 0
186 
187 Ans:
188     4
189     16
190 */
View Code

 

转载于:https://www.cnblogs.com/zaq19970105/p/11182735.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/410719.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2021泉州高考学校成绩查询,2021泉州市地区高考成绩排名查询,泉州市高考各高中成绩喜报榜单...

距离2018年高考还有不到一个月的时间了&#xff0c;很多人在准备最后冲刺的同时&#xff0c;也在关心高考成绩。2018各地区高考成绩排名查询,高考各高中成绩喜报榜单尚未公布&#xff0c;下面是往年各地区高考成绩排名查询,高考各高中成绩喜报榜单&#xff0c;想要了解同学可以…

转载:CEO如何“养好CIO同时管好CIO”?

http://www.enet.com.cn/article/2010/1214/A20101214800028.shtml 在现代企业经营理论中&#xff0c;有个着名的“二八定律”&#xff0c;即人才对企业贡献而言&#xff0c;常常是20%的人做出了80%的企业效益。显而易见&#xff0c;这“20%”就是企业的骨干与核心。而这“20%”…

PL/SQL中模拟EBS上下文

有时&#xff0c;我们需要查询的表或视图&#xff0c;是具有OU屏蔽的&#xff0c;这时我们就需要模拟EBS中的上下文来实现查询数据。 BEGIN fnd_global.apps_initialize(user_id >1,resp_id > 2,resp_appl_id >3); mo_global.init(ONT); END; 上述参数的获取&#xff…

[html] 一般习惯把js写在</body>前,但有例外的情况吗?说说看

[html] 一般习惯把js写在前&#xff0c;但有例外的情况吗&#xff1f;说说看 js的放置位置有三种&#xff1a; &#xff08;1&#xff09;放在head标签内 &#xff08;2&#xff09;放在body标签内 &#xff08;3&#xff09;外部script个人简介 我是歌谣&#xff0c;欢迎和大…

计算机桌面设计总结及体会,计算机基础学习心得

计算机基础学习心得 相关内容:计算机硬件是指计算机系统中由电子&#xff0c;机械和光电元件等组成的各种物理装置的总称。下面是第一范文网带来的计算机硬件实习心得体会&#xff0c;欢迎欣赏。计算机硬件实习心得体会一&#xff1a;一、实习目的&#xff1a;1、练习和巩固识别…

POJ 2676 Sudoku【DancingLinks,数独】

http://poj.org/problem?id2676POJ 2676 Sudoku也是求解规模为9*9的数独问题&#xff0c;与POJ 3074 Sudoku相同的问题&#xff0c;只是修改了输入输出格式而已。。。所以也不废话了&#xff0c;嘿嘿。。。 #include<stdio.h> #include<string.h> const int MAX_C…

Unittest方法 -- 测试固件(TestFixture)

前置和后置 1.setUp&#xff1a;在写测试用例的时候&#xff0c;每次操作其实都是基于打开浏览器输入对应网址这些操作&#xff0c;这个就是执行用例的前置条件。2.tearDown&#xff1a;执行完用例后&#xff0c;为了不影响下一次用例的执行&#xff0c;一般有个数据还原的过程…

[html] 如何关闭HTML页面在IOS下的键盘首字母自动大写?

[html] 如何关闭HTML页面在IOS下的键盘首字母自动大写&#xff1f;&#xff1f; autocapitalize"none"或"off"个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一…

所谓语音合成 是计算机根据语言学,计算语言学完整1

计算语言学第一节计算语言学概说概念&#xff1a;计算语言学(computational linguistics)是用计算机研究和处理自然语言的一门新兴边缘学科。涉及语言学、计算机科学、数学等多个领域。旨在通过建立形式化的数学模型&#xff0c;来分析处理自然语言&#xff0c;并在计算机上用程…

再深入 HTTP Referer【转】

简言之&#xff0c;HTTP Referer是header的一部分&#xff0c;当浏览器向web服务器发送请求的时候&#xff0c;一般会带上Referer&#xff0c;告诉服务器我是从哪个页面链接过来的&#xff0c;服务器籍此可以获得一些信息用于处理。 比如从我主页上链接到一个朋友那里&#xff…

剑指:树的子结构

题目描述输入两棵二叉树 A、B&#xff0c;判断 B 是不是 A 的子结构。 我们规定空树不是任何树的子结构。 样例 树 A&#xff1a; 8 / \ 8 7 / \ 9 2 / \ 4 7 树 B&#xff1a; 8 / \ 9 2 返回 true ,因为 B 是 A 的子结构。 解法递归方式遍历&#xff1a; 在树 A 中找到和树 B…

[html] 页面的重绘和回流是什么?

[html] 页面的重绘和回流是什么&#xff1f; 由于节点的几何属性发生改变或者由于样式发生改变而不会影响布局的&#xff0c;称为重绘。回流是布局或者几何属性需要改变就称为回流。回流必定会发生重绘&#xff0c;重绘不一定会引发回流。个人简介 我是歌谣&#xff0c;欢迎和…

QT中IDirect3DDevice9的Present方法失败情况的处理笔记

这几天在试着使用QT做编辑器&#xff0c;然后打算使用Irrlicht作为渲染引擎。结果在集成的时候遇到了问题。 使用了Irrlicht论坛里面有人提供的QIrrlichtWidget&#xff0c;结果什么都画不出来。仔细跟踪了一下&#xff0c;结果是IDirect3DDevice9的Present函数返回了E_FAIL。 …

html5图片长按保存,一文彻底解决HTML5页面中长按保存图片功能

$.fn.longPress function(fn) {let timeout 0;const $this this;for (let i 0; i < $this.length; i) {$this[i].addEventListener(touchstart, () > {timeout setTimeout(fn, 800); // 长按时间超过800ms&#xff0c;则执行传入的方法}, false);$this[i].addEventL…

[html] 页面的重绘和回流是什么?

[html] 页面的重绘和回流是什么&#xff1f; 由于节点的几何属性发生改变或者由于样式发生改变而不会影响布局的&#xff0c;称为重绘。回流是布局或者几何属性需要改变就称为回流。回流必定会发生重绘&#xff0c;重绘不一定会引发回流。

(转)深入理解Java中的final关键字

转自&#xff1a;http://www.importnew.com/7553.html Java中的final关键字非常重要&#xff0c;它可以应用于类、方法以及变量。这篇文章中我将带你看看什么是final关键字&#xff1f;将变量&#xff0c;方法和类声明为final代表了什么&#xff1f;使用final的好处是什么&…

jsp servlet中的过滤器Filter配置总结(转)

在Java web开发中常会使用到功能强大的过滤器&#xff0c;他毕竟能给我们带来很大的方便&#xff0c;但是针对过滤的资源我们需要详细的了解他们在web.xml中的配置信息。这个根据几种常用的不同情况进行了总结&#xff1a; 1。如果要映射过滤应用程序中所有资源&#xff1a; &l…

[html] 你最喜欢H5的哪些功能?为什么?

[html] 你最喜欢H5的哪些功能&#xff1f;为什么&#xff1f; 我最喜欢H5中包含的地理定位功能&#xff0c;通过调用geolocation api&#xff0c;用户允许定位后即可获取客户端wgs84坐标信息&#xff1b;相比于某些服务商如IP Geolocation API、百度地图 &#xff08;仅限于国…

关于spring MVC 绑定json字符串与实体类绑定

1 如果前台传json字符串&#xff0c;后台用RequestBody 接收前端"content-Type":"application/json",2 前台用form表单形式提交 后台直接写实体类参数"content-Type":"application/x-www-form-urlencoded",转载于:https://www.cnblog…

fedora下配置ipv6 dns服务器

操作系统&#xff1a;fedora14 DNS版本&#xff1a;dnsmasq2.52 或者 bind9.x dnsmasq2.52是fedora14自带的&#xff0c;所以我选择了这个&#xff0c;而且使用起来也很方便&#xff0c;是一种轻量级的dns server&#xff0c;相对来说bind就比较专业&#xff0c;但是搭建很复杂…