Codeforces 803D Magazine Ad【二分+贪心】
来源:互联网 发布:c语言随机函数怎么用 编辑:程序博客网 时间:2024/06/05 10:02
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more than one hyphen.
It is guaranteed that there are no adjacent spaces and no adjacent hyphens. No hyphen is adjacent to space. There are no spaces and no hyphens before the first word and after the last word.
When the word is wrapped, the part of the word before hyphen and the hyphen itself stay on current line and the next part of the word is put on the next line. You can also put line break between two words, in that case the space stays on current line. Check notes for better understanding.
The ad can occupy no more that k lines and should have minimal width. The width of the ad is the maximal length of string (letters, spaces and hyphens are counted) in it.
You should write a program that will find minimal width of the ad.
The first line contains number k (1 ≤ k ≤ 105).
The second line contains the text of the ad — non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed106 characters.
Output minimal width of the ad.
4garage for sa-le
7
4Edu-ca-tion-al Ro-unds are so fun
10
Here all spaces are replaced with dots.
In the first example one of possible results after all word wraps looks like this:
garage.for.sa-le
The second example:
Edu-ca-tion-al.Ro-unds.are.so.fun
题目大意:
给你一个字符串,其中两两单词之间用‘-’或者是空格分开,问你分组的最小长度,使得每个单词只能处于一个分组中并且分组数小于等于k.
思路:
很显然有单调性,如果长度len可以满足条件,那么长度len+1也一定满足条件,同理len+2更满足条件。
所以我们二分答案,然后贪心check一下即可。
尽可能将一个单词分到一组中。
注意一些细节,因为上界是1e6.而分组数最大可以到1e5.如果我们判定mid*kk和n的大小的时候,我们如果两个int相乘会爆int.
所以不妨将所有数据都设定为LL.稳妥更多。
- Codeforces 803D Magazine Ad【二分+贪心】
- codeforces 803D Magazine Ad
- CodeForces 803D Magazine Ad
- codeforces 803D Magazine Ad
- Codeforces 803D Magazine Ad 题解
- Magazine Ad CodeForces
- CF Educational Codeforces Round 20 D. Magazine Ad
- 「codeforces 」教育场20-D.Magazine Ad
- CF803D:Magazine Ad(二分)
- Codeforces 609D 贪心+二分
- codeforces 732D (二分 贪心)
- 【codeforces 732D】【二分+贪心】
- Codeforces #732D 二分 贪心
- CodeForces 363D 【二分+贪心】
- CodeForces 614D 二分+贪心
- Codeforces 479D Long Jumps(贪心+二分)
- Exams Codeforces Round#377-D(贪心+二分)
- codeforces 377D exam贪心判定+二分
- 崇志宏 【转载】深度学文献阅读路径图---东南大学
- java中的字节流和字符流的区别是什么?
- 三、Hadoop的RPC框架运行机制
- web.鼠标.调用坐标函数
- 删除链表中重复的结点
- Codeforces 803D Magazine Ad【二分+贪心】
- WAS监控工具WAS Performance Tunning Toolkit
- Path Sum III
- 欢迎使用CSDN-markdown编辑器
- R语言学习笔记(五)
- 项目开发任务及流程记录
- 网络编程(上)
- [JQuery $()XXXX is not a function] 已解决
- VMWare 12 Pro 安装 MAC OS Sierra