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. hibernate多表查询

    一对多进行查询(用懒加载的模式) 查找区域所对应的街道: Dao: public Qu selQu(String dno){ Session session=HibernateSessionFacto ...

  2. Elasticsearch中的分词器比较及使用方法

    Elasticsearch 默认分词器和中分分词器之间的比较及使用方法 https://segmentfault.com/a/1190000012553894 介绍:ElasticSearch 是一个 ...

  3. android中常见的命名及其特点详解

    Paseal命名法 Paseal命名法特点:String MyName-DelphiInt MyAge每个单词首字母大写 Camel命名法 Camel(驼峰的意思)命名法特点:String myNam ...

  4. BZOJ4472 JSOI2015salesman(树形dp)

    相当于选一个包含根的连通块使权值和最大,且每个点的儿子选取数量有限制.那么显然贪心的在所有子树中选比较大的就可以了.至于方案是否唯一只需要看选的子树是否可以替换,注意dp值为0的情况. #includ ...

  5. BZOJ2818 GCD 【莫比乌斯反演】

    2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MB Submit: 6826 Solved: 3013 [Submit][Status][Discuss ...

  6. 洛谷 P2529 [SHOI2001]击鼓传花 解题报告

    P2529 [SHOI2001]击鼓传花 题意:求出\(n!\)末尾最后一位非0数字 数据范围:\(n<=10^{100}\) 我们从简单的开始考虑 1.显然,\(n!\)可以被这么表示 \(n ...

  7. oralce的客户端sqlplus

    安装完oracle后,默认的客户端是sqlplus,还有一个公司常用的是PLSQLdeveloper 客户端软件,另外Navicat primie这个可以连接mysql.sqlserver.oracl ...

  8. 构建一个类jq的函数库

    jqfree core var $ = function(selector, context) { return new $.fn.init(selector, context); }; $.fn = ...

  9. ERROR: Found lingering reference file hdfs

    Found lingering reference异常 ERROR: Found lingering reference file hdfs://jiujiang1:9000/hbase/month_ ...

  10. (转)用python获取页面返回的cookie

    网址如下: crifan:http://www.crifan.com/get_cookie_from_web_response_in_python/ . . . .