【题目链接】: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. BZOJ 2631 tree 动态树(Link-Cut-Tree)

    题目大意:维护一种树形数据结构.支持下面操作: 1.树上两点之间的点权值+k. 2.删除一条边.添加一条边,保证加边之后还是一棵树. 3.树上两点之间点权值*k. 4.询问树上两点时间点的权值和. 思 ...

  2. Linux 强行终止

    kill -9 pid pid是进程号 -9 代表的是数字 INT 2 这个就是你在bash下面用Ctrl+C 来结束一个程序时,bash会向进程发送这个信号,默认的,进程收到这个程序会结束. 你可以 ...

  3. Android笔记之网络状态推断

    1.首先当然得在 manifest 中加入检查网络状态的权限: <uses-permission android:name="android.permission.ACCESS_NET ...

  4. QT4.86写中文XML

    网上都语焉不详.举例XML使用的时候,全部都是英文内容,当然不会失败了.尤其我还以VS2008编译,编译器的Character Set就有三种设置,配上QTextCodec::setCodecForC ...

  5. SpringMVC 拦截器不拦截静态资源的三种处理方式方法

    方案一.拦截器中增加针对静态资源不进行过滤(涉及spring-mvc.xml) <mvc:resources location="/" mapping="/**/* ...

  6. I NEED A OFFER!(hdoj--1203--01背包)

    I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDU1412 {A} + {B}

    2019-05-17 10:15:01 每个元素之间有一个空格隔开. 每行最后一的元素后面没有空格,区别于HDU人见人爱A - B 注意使用STL的时候要清空 .  a.clear(); #inclu ...

  8. js判读周末以及节假日

    两个链接,搞定! http://bbs.csdn.net/topics/10417668 http://www.jb51.net/article/131660.htm

  9. 移动测试基础—adb、monkey命令

    最近打算把移动测试相关的知识总结一下,先从基础开始吧,总结一下adb.monkey命令 adb常用命令总结 adb / adb -help 使用帮助 adb devices 查看连接到电脑的设备 ad ...

  10. maven使用杂记

    maven test使用记录 运行指定的测试类:     >mvn test -Dtest=[ClassName] 运行测试类中指定的方法:(这个需要maven-surefire-plugin: ...