803D - Magazine Ad

思路:

  二分答案+贪心;

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 1000006 int k,ai[maxn],cnt,num,len,maxlen; char ch[maxn]; bool check(int lit)
{
int pos=,times=;
for(int i=;i<=num;i++)
{
if(pos+ai[i]<=lit) pos+=ai[i];
else times++,pos=ai[i];
}
if(times>=k) return false;
return true;
} int main()
{
scanf("%d",&k);getchar();
gets(ch);
for(int i=;true;i++)
{
cnt++;
if(ch[i]=='-'||ch[i]==' ') ai[++num]=cnt,cnt=;
if(ch[i+]==&&ch[i+]==)
{
len=i+;
ai[++num]=cnt;
break;
}
}
for(int i=;i<=num;i++) maxlen=max(maxlen,ai[i]);
int l=maxlen,r=len,ans;
while(l<=r)
{
int mid=l+r>>;
if(check(mid)) ans=mid,r=mid-;
else l=mid+;
}
cout<<ans;
return ;
}

AC日记——Magazine Ad codeforces 803d的更多相关文章

  1. Magazine Ad CodeForces - 803D(二分 + 贪心,第一次写博客)

    Magazine Ad The main city magazine offers its readers an opportunity to publish their ads. The forma ...

  2. Magazine Ad CodeForces - 803D (二分+贪心)

    The main city magazine offers its readers an opportunity to publish their ads. The format of the ad ...

  3. AC日记——Cards Sorting codeforces 830B

    Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  4. AC日记——Card Game codeforces 808f

    F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...

  5. AC日记——Success Rate codeforces 807c

    Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  6. AC日记——T-Shirt Hunt codeforces 807b

    T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  7. AC日记——Broken BST codeforces 797d

    D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...

  8. AC日记——Array Queries codeforces 797e

    797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...

  9. AC日记——Maximal GCD codeforces 803c

    803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...

随机推荐

  1. 【Linux】Linux修改openfile和max user processes?

    #当时测试虚机为centos7.4版本: # 在/etc/security/limits.conf文件末尾添加如下命令: *     soft     nproc   1314 *     hard  ...

  2. win7 redis

    <?php /* windows下php安装redis扩展 php_redis下载地址:https://pecl.php.net/package/redis 点击redis安装版本后面的 DLL ...

  3. Python 装饰器和抽象类

    #装饰器:对类或者函数进行功能的扩展 ''' #第一步:基本函数 def la(): print('脚踏黄河两岸,手拿机密文件,前面机枪扫射,后面炮火连天') #调用函数 la() la() #第二步 ...

  4. NOIP2018复赛 游记

    Day -? 停了两个星期的课,逃了一场期中考试.随便做了点题并不知道有什么用.见不到夫人很难受. Day 0 依然没有跟学校走.据说今年合肥居然不下雨,印象里每年这个时候来到这里都是阴雨连绵……突然 ...

  5. vThunder 安装

    vThunder 安装 安装镜像下载地址 https://glm.a10networks.com/downloads A10 全球授权许可管理  https://glm.a10networks.com ...

  6. ContestHunter#17-C 舞动的夜晚

    Description: L公司和H公司举办了一次联谊晚会.晚会上,L公司的N位员工和H公司的M位员工打算进行一场交际舞.在这些领导中,一些L公司的员工和H公司的员工之间是互相认识的,这样的认识关系一 ...

  7. malloc calloc realloc

    三个函数的申明分别是: void* realloc(void* ptr, unsigned newsize); void* malloc(unsigned size); void* calloc(si ...

  8. github导入springboot maven项目

    1.在GitHub里force喜欢的项目,获取GitHub项目地址,eclipse---import---project from git---clone uri---next---finish,项目 ...

  9. eclipse+jetty+web项目调试---不显示源码

    本人eclipse版本:JUNO 1.问题现象:显示源码时,不显示箭头(指示到哪行) 解决办法: debug configurations  --->Goals设置参数  clean -X je ...

  10. Dozer数据对象转换神器

    Dozer数据对象转换神器