【题目链接】:http://codeforces.com/contest/803/problem/D

【题意】



给你一个字符串;

其中的空格和连字符表示可以折叠的部分

(就是说能在那个位置把字符串分成两部分,且和两部分分到两行去);

这个操作能够使得原字符串不断变小;

问你最后获得的所有字符串(可能分裂成了多个,所以是”所有”)中最长的那个最短能够是多少;

(这个操作最多只能操作k次)

【题解】



二分答案;

枚举最后那个最长的长度是多少x;

现在,相当于让你最多切k-1刀;

使得k个部分,每个部分的长度都小于等于x;

问你可不可行;

这个模拟可不可行的部分贪心就能写;(加上这一段之后如果还能小于等于x,就让它们在同一段,否则到另外一段(其实也就对应了在不同的行));



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6+100; int k,nex[N],n;
char s[N]; bool ok(LL x)
{
LL now = 0,tot = 0;
for (int i = 1;i<=n; )
{
if (nex[i]-i+1>x) return false;
if (now+nex[i]-i+1<=x)
{
now+=nex[i]-i+1;
i = nex[i]+1;
}
else
{
now = 0,tot++;
}
}
if (now) tot++;
return tot<=k;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
// ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> k;char t = getchar();
gets(s+1);
n = strlen(s+1);
int be = n;
rep2(i,n,1)
{
if (isupper(s[i])||islower(s[i]))
continue;
nex[i+1] = be;
be = i;
}
nex[1] = be;
LL l = 1,r = n,ans;
while (l<=r)
{
LL mid = (l+r)>>1;
if (ok(mid))
{
ans = mid,r = mid-1;
}
else
l = mid+1;
}
cout << ans << endl;
return 0;
}

【codeforces 803D】Magazine Ad的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 787A】The Monster

    [题目链接]:http://codeforces.com/contest/787/problem/A [题意] 把b一直加a->得到x 把d一直加c->得到y 然后问你x和y可不可能有相同 ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. Android动态部署五:怎样从插件apk中启动Service

    转载请注明出处:http://blog.csdn.net/ximsfei/article/details/51072332 github地址:https://github.com/ximsfei/Dy ...

  2. hdu 2883 kebab(时间区间压缩 &amp;&amp; dinic)

    kebab Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  3. Cocos2d-X直接使用OpenGL接口

    Cocos2d-X是基于基于OpenGL ES的2D游戏引擎,所以Cocos2d-X能够直接使用OpenGL接口 首先建立一个Draw类,用于处理OpenGL接口 在Draw.h中加入以下的代码 #i ...

  4. 基于Websocket的火拼俄罗斯(基础)

    传统的HTTP请求是由浏览器发起,然后呢服务端接收到请求之后呢返回一个数据.那么这样一次来回之后呢请求就断了.但是WebSocket它不一样,它同样是由浏览器去发起一个请求但是这个请求是一个WebSo ...

  5. [Java] 总结1.5/1.6/1.7版本的特性

    开发过程中接触到了从jdk1.5---jdk1.7的使用,在不同的阶段,都使用过了jdk的一些新特性,操作起来更加方面啦!特此总结了下,以下是测试代码: JDK1.5新特性: 1.自动装箱与拆箱: I ...

  6. Comparable与Comparator源码分析

    package java.lang; import java.util.*; /** * This interface imposes a total ordering on the objects ...

  7. MongoDB Master-Slave cluster with authentication setup

    Master Server create mongo db folder with sub folders like data, conf, && log mkdir -p /opt/ ...

  8. .net core发布到IIS后502.5错误

    net core 在win7系统发布后,出现在502.5错误. 打开“开始”菜单,搜索“事件查看器”,然后选择“事件查看器”应用. 在“事件查看器”中,打开“Windows 日志”节点. 选择“应用程 ...

  9. TensorFlow-LSTM序列预测

    问题情境:已知某一天内到目前为止股票各个时刻的价格,预测接下来短时间内的价格变化. import tushare as ts import time from collections import n ...

  10. video相关简单的api

    video 关键api 1. video.pause() 2. video.play() 3. video.webkitRequestFullScreen() //全屏 4. video.curren ...