AC日记——Magazine Ad codeforces 803d
思路:
二分答案+贪心;
代码:
#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的更多相关文章
- Magazine Ad CodeForces - 803D(二分 + 贪心,第一次写博客)
Magazine Ad The main city magazine offers its readers an opportunity to publish their ads. The forma ...
- Magazine Ad CodeForces - 803D (二分+贪心)
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad ...
- AC日记——Cards Sorting codeforces 830B
Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Card Game codeforces 808f
F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...
- AC日记——Success Rate codeforces 807c
Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——T-Shirt Hunt codeforces 807b
T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Broken BST codeforces 797d
D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...
- AC日记——Array Queries codeforces 797e
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...
- AC日记——Maximal GCD codeforces 803c
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...
随机推荐
- 写一篇Hook Driver.
关于Hook,有一本书讲的比较清楚,最近刚刚看完,<Rootkits: Subverting the Windows Kernel> http://www.amazon.com/Rootk ...
- Zebra - zebra command to get printer status
/// <summary> /// determine whether the network printer is in pause. /// </summary> /// ...
- Hibernate常用方法之_查询
1.使用session的get方法 public User getUser(int id){ Session session = null; User user = null; try { sessi ...
- 【转】64位ORACLE客户端上plsql无法识别ORACLE_HOME解决方案
转自:http://www.2cto.com/database/201503/386267.html 中文显示问号 转自:http://zhidao.baidu.com/link?url=qJDmsa ...
- [CF632A]Grandma Laura and Apples
题目大意:有$n$个顾客买苹果,每个买一半的苹果,有时会送半个苹果.最后卖光了,问卖了多少钱 题解:倒退过来,可以把半个苹果当做一份来算,这样不会有小数 卡点:无 C++ Code: #include ...
- expect 实现本地到远程的scp
expect文件demo 令文件名为test.exp #!/usr/bin/expect -f set timeout -1 set pwd " set src_file [lindex $ ...
- uva 11427
题目大意:每天晚上你都玩纸牌,如果第一次赢了就高高兴兴地去睡觉:如果输了就接着玩,假设每盘游戏获胜的的概率都是p,且各盘游戏相互独立.你是一个固执的完美主义者,因此会一直玩到当晚获胜局数的比例严格大于 ...
- DotNet 学习笔记 应用状态管理
Application State Options --------------------------------------------------------------------- *Htt ...
- 下拉列表 JComboBox 的使用
下拉列表(JComboBox)通常显示一个可选条目,允许用户在一个下拉列表中选择不同条目,用户也可以在文本区内输入选择项. package first; import java.awt.FlowLay ...
- Mac git
多次提交代码,与合并的工作量成反比. in terminal window git status:查看git的状态 git add -A: 把所有不再track里的文件加入进去/ git add -u ...