codeforces 803D Magazine Ad
来源:互联网 发布:小影怎么添加网络音乐 编辑:程序博客网 时间:2024/06/10 20:44
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 exceed 106 characters.
Output minimal width of the ad.
4garage for sa-le
7
4Edu-ca-tion-al Ro-unds are so fun
10
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <queue>#include <vector>#include <set>#include <map>#define N 1000002#define maxn 2000using namespace std;typedef long long LL;int num,k;int len;char str[N];int calculate(int m){ int cnt=0; int x,j; for(int i=0; i<len;) { int flag=0; for(j=i; j<m+i&&j<len; j++) if(str[j]==' '||str[j]=='-') { flag=1; x=j; } if(flag) { cnt++; if(j==len) { i=j; } else i=x+1; } else { if(j==len) { cnt++; i=j; } else return false; } } if(cnt<=k) return true; return false;}int erfen(){ int low=0,high= len,mid; while(low<=high) { mid=(high+low)/2; if(calculate(mid))high=mid-1; else low=mid+1; } return low;}int main(){ num=0; cin>>k; getchar(); gets(str); len=strlen(str); cout<<erfen()<<endl; return 0;}
- 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
- Codeforces803D Magazine Ad
- CF803D:Magazine Ad(二分)
- d ad
- 关于AD里面3d的制作
- AD里面简易的3d制作
- AD绘制3D封装库
- CodeForces 617D CodeForces 617D
- CodeForces 101D
- CodeForces 103D
- CodeForces 222D Olympiad
- BZOJ1257 余数之和sum
- Struts拦截器和过滤器的区别
- python下使用alembic管理MYSQL数据库
- 【python】(2)网络编程
- UVALive 4513 Stammering Aliens hash+二分
- codeforces 803D Magazine Ad
- 详解 Tomcat 配置文件 server.xml
- 用递归算法计算一个自然数的二进制表示中的“1”的个数
- 网络管理(三)
- Google算法题:H-最优账户结余
- POJ 2018 斜率优化DP
- Http请求中Content-Type讲解以及在Spring MVC中的应用
- 分享下学习Kotlin的历程-变量/数据类型(1)
- FZU