http://codeforces.com/contest/738/problem/D

https://www.cnblogs.com/flipped/p/6086615.html   原

题意:海战棋游戏,长度为n的01串,1代表炸过且没有船的位置,0代表没有炸过的位置。有a个船,长度都是b,求打到一艘船至少还需要多少炸弹,并输出炸的位置。

分析:每连续的b个0就要炸一次,不然不知道有没有是不是刚好一艘船在这b个位置上面。贪心可知炸这b个的最后一个最划算。因为只要炸到一艘即可,所以答案减去a-1,即有a-1艘可以不管它。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define se second
#define fi first
const int Mos = 0x7FFFFFFF; //
const int nMos = 0x80000000; //-2147483648
const int N=2e5+; int n,a,b,k;
char g[N];
int d[N]; int main()
{
cin>>n>>a>>b>>k;
scanf("%s",g+); int cnt=,m=;
for(int i=;i<=n;i++)
{
if(g[i]=='')
{
cnt++;
if(cnt==b)
{
cnt=;
d[m++]=i;
}
}
if(g[i]=='') cnt=;
}
m-=(a-);
cout<<m<<endl;
for(int i=;i<m-;i++)
cout<<d[i]<<" ";
cout<<d[m-]<<endl;
}

Codeforces 729D Sea Battle(简单思维题)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces 738D. Sea Battle 模拟

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

  4. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  5. E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题

    E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces 752C - Santa Claus and Robot - [简单思维题]

    题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...

  7. 2019浙大校赛--G--Postman(简单思维题)

    一个思维水题 题目大意为,一个邮递员要投递N封信,一次从邮局来回只能投递K封.求最短的投递总距离.需注意,最后一次投递后无需返回邮局. 本题思路要点: 1.最后一次投递无需返回邮局,故最后一次投递所行 ...

  8. Codeforces 515C 题解(贪心+数论)(思维题)

    题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...

  9. Codeforces 1188B - Count Pairs(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...

随机推荐

  1. sql-获取重复和删除重复数据

    //获取相同用户名的数据 //删除相同的数据,保留最大的id或者最小的id min(id) delete from user where id not in(select max(id) from u ...

  2. 高级UI-Snackbar

    在与用户的交互中,最为常用的Toast和Dialog,但二者都存在其局限,Toast无法与用户进行交互,Dialog虽然可以与用户交互,但却会阻断用户操作的连贯性,介于二者之间的平衡,Snackbar ...

  3. storm是如何保证at least once语义的?

    storm中的一些原语: 要说明上面的问题,得先了解storm中的一些原语,比如: tuple和messagetuple:在storm中,消息是通过tuple来抽象表示的,每个tuple知道它从哪里来 ...

  4. Clustering and Exploring Search Results using Timeline Constructions (paper2)

    作者:Omar Alonso 会议:CIKM 2009 摘要: 截至目前(2009),通过提取文档中内嵌的时间信息来展现和聚类,这方面的工作并不多. 在这篇文章中,我们将提出一个“小插件”增添到现有的 ...

  5. 在Settings.db数据库中添加一项新的设置(Settings默认设置)

    Settiings的数据默认存放在com.android.providers.settings/database/settings.db中 数据库中的默认数据在frameworks/base/pack ...

  6. Redis 常用命令学四:列表类型命令

    1.在列表两端增加值的命令 127.0.0.1:6379> lpush 1 (error) ERR wrong number of arguments for 'lpush' command 1 ...

  7. 原生js分页器插件

    window.page = function page(ele, para) { this.ele = document.querySelector(ele); this.options = { co ...

  8. (二十九)JSP之国际化

    导入 <%@ taglib url="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 创建三个语 ...

  9. 奇妙的算法【7】-贪婪算法-dp

    问题1描述:[贪婪算法,Dijistra算法] ①有一只兔子要从一个N*N的二维矩阵方格中从上跳到下面: ②每次只能向左或向下,越过一个方格,跳到下一个方格中: ③被越过的方格中的数值,表示该兔子越过 ...

  10. JDBC 学习复习8 C3P0数据源使用

    C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展.目前使用它的开源项目有Hibernate,Spring等. c3p0与dbcp区别 dbcp ...