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 ...
随机推荐
- 模拟ORA-26040: Data block was loaded using the NOLOGGING option
我们知道通过设置nologging选项.能够加快oracle的某些操作的运行速度,这在运行某些维护任务时是非常实用的,可是该选项也非常危急,假设使用不当,就可能导致数据库发生ORA-26040错误. ...
- 一起talk C栗子吧(第二十五回:C语言实例--二分查找)
各位看官们,大家好,上一回中咱们说的是顺序查找的样例,这一回咱们说的样例是:二分查找.闲话休 提,言归正转. 让我们一起talk C栗子吧. 看官们,我们在上一回中说了查找的相关内容,而且介绍了一种查 ...
- linux 环境 tomcat 莫名奇妙挂掉
::-exec-] org.apache.coyote.http11.Http11Processor.service Error processing request java.lang.NullPo ...
- Android实例-多窗口的切换
Android实例-多窗口的切换 1.图片一是程序运行后的界面. 2.图片二是点击"非模态显示"的界面. 3.图片三是点击"模诚显示"的界面(提示平台不支持). ...
- poj3411
Paid Roads Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6549 Accepted: 2427 Descri ...
- 用jQuery实现简单的DOM操作
通过jQuery创建元素节点:$oLi = $("<li></li>");这样我们就创建了一个li标签 如果想在元素节点中添加文本的话也挺简单:$oLi = ...
- powershell Start-Sleep
秒: Start-Sleep –s 10 ,毫秒) Start-Sleep –m 10000 语法 Start-Sleep [-seconds] <int> [<CommonPara ...
- mysql 中事件
# 创建存储过程 /* delimiter // create procedure test() begin update test SET name = date_format(now(),'%Y- ...
- convention over configuration 约定优于配置 按约定编程 约定大于配置 PEP 20 -- The Zen of Python
为什么说 Java 程序员必须掌握 Spring Boot ?_知识库_博客园 https://kb.cnblogs.com/page/606682/ 为什么说 Java 程序员必须掌握 Spring ...
- <2014 04 29> c/c++常用库总结
C 标准库 ============================================================================================== ...