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 ...
随机推荐
- Go开发的体会【转】
摘自 http://studygolang.com/articles/5069 再次表示感谢,学习了.
- sublime text 3 并列显示
alt+shift+1:显示一列 alt+shift+2:显示二列 alt+shift+3:显示三列 ......
- linux jdk 6 版本下载
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-41940 ...
- Oracle Instant Client的安装和使用
转自:https://www.cnblogs.com/chinalantian/archive/2011/09/09/2172145.html 根据自己需求到Oracle网站(http://www.o ...
- 如何看懂ORACLE执行计划
如何看懂Oracle执行计划 一.什么是执行计划 An explain plan is a representation of the access path that is taken when a ...
- 12.php中无比坑爹的构造函数。
当你在php类中,写一个构造方法时,记得,一定要用__这是两个下划线,而不是一个.......... <?php class Car { // function _construct() { / ...
- Frequent Values-线段树求解出现最多的数
Frequent Values(poj 3368) 注意:以下答案为离线作答结果,并非能通过poj,若要通过poj,需要修改函数接口,因为以下程序接受半封闭区间(s,e],同时还需要修改输入数据的顺序 ...
- 我的Android进阶之旅------>解决DownloadManager报错java.lang.SecurityException: Invalid value for visibility: 2
1.问题描述 今天使用Android系统的DownloadManager进行下载操作时,爆了如下所示的错误: java.lang.RuntimeException: Unable to start s ...
- Android主页导航:fragment+viewpager
简单实现Fragment+ViewPager实现主页导航控制,效果如下: 一.activity_main.xml布局文件: <?xml version="1.0" encod ...
- android6.0获取通讯录权限
android6.0中,获取通讯录的权限是 <uses-permission android:name="android.permission.GET_ACCOUNTS" ...