codeforces 738
D: 题意:一行1*n的格子放船只,船数为a,船的长度为b,每格为0或1,1表示该格并不是船只的一部分,找出最少的格子数使得射击这些格子至少能打中一艘船。
思路:船的长度为b,即每段连续的长度为b的0的串都可以放下一只船,射击点为最后一个格子时最优,找出所有的可以放船的位置res个,选择其中的res-a+1个位置。
#include<bits/stdc++.h>
using namespace std;
char str[];
int op[]={};
int main() {
int n,a,b,k,cnt=,tmp,l,t=;
scanf("%d%d%d%d%s",&n,&a,&b,&k,str);for(int i=;i<n;++i) {
if(str[i]=='') ++t;
if(str[i]=='') t=;
if(t==b) {
op[cnt++]=i+;
t=;
}
}
cnt-=a-;
printf("%d\n",cnt);
for(int i=;i<cnt;++i) {
printf("%d%c",op[i],(i==cnt-)?'\n':' ');
}
return ;
}
E 题意:一个公司有n个人,只有一个主管编号为s,除主管外的n-1个人有且仅有一个直接上司,但他的直接上司的上司也算他的上司。给出一个数列为1-n号员工的上司的数目,问至少修改几个值使得该数列为正确。
思路:要想使得数列正确,数列必须为连续的非降数列,如0111234,且数列中的0只有一个且编号为s。
如果数列发生错误,则肯定是出现断裂或编号不为s的0,如00234,编号不为s的0必为要修改的,每次出现断裂时先用0补断裂,然后不断用目前最大的数补断裂,如果无数可补,则答案+1,结束。
#include<bits/stdc++.h>
using namespace std;
int a[]={},cnt=;
int main() {
int n,s,last,ans=;
scanf("%d%d",&n,&s);
for(int i=;i<=n;++i) {
scanf("%d",&a[i]);
if(i!=s&&!a[i]) ++cnt;
}
if(a[s]!=) ++ans,a[s]=;
sort(a+,a+n+);
last=n;
int x=upper_bound(a+,a+n+,)-a;
if(x==n) {
printf("%d\n",cnt+ans);
return ;
}
int f=;
for(int i=x;i<=last&&f;++i) {
while(a[i]>a[i-]+) {
if(cnt) --cnt,++a[i-];
else {
if(last>i) {
--last,++a[i-];
}
else {
++ans;
f=;
break;
}
}
++ans;
}
}
printf("%d\n",ans+cnt);
return ;
}
codeforces 738的更多相关文章
- Codeforces Round #738 (Div. 2)
Codeforces Round #738 (Div. 2) 跳转链接 A. Mocha and Math 题目大意 有一个长度为\(n\)的数组 可以进行无数次下面的操作,问操作后数组中的最大值的最 ...
- Codeforces Round #738 (Div. 2) D2题解
D2. Mocha and Diana (Hard Version) 至于D1,由于范围是1000,我们直接枚举所有的边,看看能不能加上去就行,复杂度是\(O(n^2logn)\).至于\(n\)到了 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- 【codeforces 738E】Subordinates
[题目链接]:http://codeforces.com/problemset/problem/738/E [题意] 给你一个类似树形的关系; 然后告诉你某个人头顶上有多少个上司numi; 只有fat ...
- 【57.97%】【codeforces Round #380A】Interview with Oleg
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【42.86%】【Codeforces Round #380D】Sea Battle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- Volley 源码分析
Volley 源码分析 图片分析 要说源码分析,我们得先看一下官方的配图: 从这张图中我们可以了解到 volley 工作流程: 1.请求加入优先队列 2.从缓存调度器中查看是否存在该请求,如果有(没有 ...
- 大数据技术大合集:Hadoop家族、Cloudera系列、spark、storm【转】
大数据我们都知道hadoop,可是还会各种各样的技术进入我们的视野:Spark,Storm,impala,让我们都反映不过来.为了能够更好 的架构大数据项目,这里整理一下,供技术人员,项目经理,架构师 ...
- linux jdk 6 版本下载
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-41940 ...
- java的double类型如何精确到一位小数?
java的double类型如何精确到一位小数? //分钟转小时vacationNum = (double)Math.round(vacationNum/60*10)/10.0;overTimeNum ...
- delphi ----寻找控件,以字符串类型的名称控件
vari :Integer;beginfor i := 1 to 10 do(FindComponent('Edit'+inttostr(i)) as TEdit).Text := inttostr( ...
- Design Pattern – Proxy, Adapter, Facade, Mediator
这几个模式比较类似, 都是用作interface, 但有所不同 Proxy, 特点是以假乱真, client在使用的时候就和在使用真正的object一样, 接口完全一致, proxy和object的交 ...
- wsgi pep333
转自:https://www.aliyun.com/jiaocheng/444966.html?spm=5176.100033.1.11.559a7C 摘要:wsgi介绍参考:pep333wsgi有两 ...
- 用gunicorn+gevent启动Flask项目
转自:https://blog.csdn.net/dutsoft/article/details/51452598 Flask,webpy,Django都带着 WSGI server,当然性能都不好, ...
- Compilation failed: internal java compiler error
在Idea中编译时出现这个错误:Error:java: Compilation failed: internal java compiler error. Information:Using java ...
- MySQL小记
一.MyISAM和InnoDB MyISAM引擎是不支持事务的,所以一般开发Mysql的引擎使用InnoDB. 事务处理上方面: MyISAM类型的表强调的是性能,其执行速度比InnoDB类型更快,但 ...