题目链接:http://codeforces.com/contest/738/problem/D

题意:1*n的格子里有a条长为b的船。有一个人射了k发子弹都没打中船,现在问最少再打多少次一定能保证射到一搜。

统计出每一个子块中最多能多少条船,贪心地从左到右排列,记下船尾。假设有m条,那么除了m-a条船,剩下的位置一定能打中一条。就是打m-a+1个地方,随便打m-a+1个船尾就行了。

 #include <bits/stdc++.h>
using namespace std; const int maxn = ;
int n, a, b, k;
char s[maxn];
vector<int> shoot;
vector<int> seg;
vector<int> bg, ed; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d%d%d%d",&n,&a,&b,&k)) {
scanf("%s", s+);
int cnt = ;
seg.clear();
for(int i = ; i <= n; i++) {
if(s[i] == '') {
cnt = ;
}
else if(s[i] == '') {
cnt++;
if(cnt == b) {
seg.push_back(i);
cnt = ;
}
}
}
int sz = seg.size();
printf("%d\n", sz);
sz = sz - a + ;
for(int i = ; i < sz; i++) {
printf("%d%c", seg[i], i == sz - ? '\n' : ' ');
}
}
return ;
}

[CF738D]Sea Battle(贪心)的更多相关文章

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

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

  2. Sea Battle

    Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  3. Codeforces Round #380 (Div. 2)D. Sea Battle

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

  4. Codeforces 738D. Sea Battle 模拟

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

  5. Codeforces #380 div2 D(729D) Sea Battle

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

  6. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟

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

  7. Sea Battle<海战>(思路题)

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

  8. Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题

    Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...

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

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

随机推荐

  1. 帮初学者改代码——有多少青春可以挥霍之“c语言 多重排序”

    原文:“c语言 多重排序” 原代码: #include<stdio.h> #include<string.h> struct A { char name[100]; int g ...

  2. string与char之间的互相转换

    string对象是一种很强大的存在哈~~ 1. string转const char* string s = "abc"; const char* c_s = s.c_str(); ...

  3. Javascript 类与静态类的实现-js面向对象

    在Javascript里,对面向对象并没有一个直接的实现,对于代码方面也是非常的灵活. 今天所要说的就是,如何在Javascript里写类与静态类,这是本人一惯用的方法,你也可以有更为方便的,也可以发 ...

  4. php删除多重数组对象属性,重新赋值的方法

    php删除多重数组对象属性,重新赋值的方法 实例:sphinx搜索出来的结果,要去掉某个属性值:$cl = new SphinxClient ();$query = $cl->Query ( $ ...

  5. activeMQ下载,安装,启动,关闭

    1.新建一个文件夹activeMQ   mkdir /server 2.授权    chmod 777 /server 3.下载activeMQ安装包,拷贝到/activeMQ目录下 apache-a ...

  6. 通达OA 指纹考勤机接口 源代码

    通达oa2011已经支持 指纹考勤机  但只限中控iclock660 这款2000大洋的型号 通过本文的开发接口,可以与任意一款指纹机集成, 需求指纹机管理软件能实时保存数据 我这里用的是 中控u16 ...

  7. ACM题目————一笔画问题

    描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来. 规定,所有的边都只能画一次,不能重复画. 输入 第一行只有一个正整数N(N< ...

  8. Android动画的使用总结

    1.补间动画(透明渐变.平移.旋转.缩放.组合) 方法一:通过xml文件设置 1-1:创建:res/anim 1-2:java代码写调用 Animation a = AnimationUtils.lo ...

  9. javaScript去除空格或换行

    js 去掉空格.回车.换行 1 releaseDesc = releaseDesc.replace(/\ +/g,"").replace(/[\r\n]/g,"" ...

  10. JAVA基础知识之多线程——线程通信

    传统的线程通信 Object提供了三个方法wait(), notify(), notifyAll()在线程之间进行通信,以此来解决线程间执行顺序等问题. wait():释放当前线程的同步监视控制器,并 ...