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的更多相关文章

  1. Codeforces Round #738 (Div. 2)

    Codeforces Round #738 (Div. 2) 跳转链接 A. Mocha and Math 题目大意 有一个长度为\(n\)的数组 可以进行无数次下面的操作,问操作后数组中的最大值的最 ...

  2. Codeforces Round #738 (Div. 2) D2题解

    D2. Mocha and Diana (Hard Version) 至于D1,由于范围是1000,我们直接枚举所有的边,看看能不能加上去就行,复杂度是\(O(n^2logn)\).至于\(n\)到了 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  7. 【codeforces 738E】Subordinates

    [题目链接]:http://codeforces.com/problemset/problem/738/E [题意] 给你一个类似树形的关系; 然后告诉你某个人头顶上有多少个上司numi; 只有fat ...

  8. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【42.86%】【Codeforces Round #380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. select标签设置只读的方法(下拉框不可选但可传值)

    1. <select id="s1" name="s1" onfocus="this.defaultIndex=this.selectedInd ...

  2. 学习tornado

    http://old.sebug.net/paper/books/tornado/ http://demo.pythoner.com/itt2zh/index.html http://tornado- ...

  3. http协议详解(1)

    HTTP协议报文格式 接下来我们看看HTTP协议(Hypertext Transfer Protocol――超文本传输协议)浏览器端(客户端)向WEB服务器端访问页面的过程和HTTP协议报文的格式. ...

  4. jQuery Validation Engine 表单验证,自定义规则验证方法

    jQuery Validation Engine 表单验证说明文档http://code.ciaoca.com/jquery/validation-engine/ js加到jquery.validat ...

  5. 《JAVA多线程编程核心技术》 笔记:第六章:单例模式与多线程

    一.立即加载/"饿汉模式"和延迟加载/"懒汉模式" 立即加载(又称饿汉模式):在使用类的时候已经将对象创建完毕,常见实现方法是直接new实例化 延迟加载(又称懒 ...

  6. Contos更换python版本

    1.查看版本 #python -VPython 2.6.6 2.安装前准备,安装相关库#yum install gcc gcc-c++ autoconf automake#yum install op ...

  7. 详解JMeter函数和变量(转载)

    详解JMeter函数和变量(1) JMeter函数可以被认为是某种特殊的变量,它们可以被采样器或者其他测试元件所引用.函数调用的语法如下: ${__functionName(var1,var2,var ...

  8. springcloud 开发时快速剔除无用服务

    注册中心配置: # 关闭保护机制 eureka.server.enable-self-preservation=false #剔除失效服务间隔 eureka.server.eviction-inter ...

  9. ansible应用

    前言: 假如让你在一组服务器安装某个软件,服务器少的话还可以接受,但如果有上百台服务器的话,这样会耗费大量时间,在这时候Ansible就由此而生:总之Ansible提供的很多模块十分强大. 一.关于a ...

  10. mysql中变量的定义

    mysql中的变量定义 mysql的变量分为系统变量和用户变量,mysql系统定义的变量是系统变量,用户自己定义的变量为用户变量.对于系统变量,用户只能够改变它的值不能够创建新的系统变量.对于用户变量 ...