Codeforces 729D Sea Battle(简单思维题)
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(简单思维题)的更多相关文章
- 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 ...
- 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 ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- 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 ...
- 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 ...
- Codeforces 752C - Santa Claus and Robot - [简单思维题]
题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...
- 2019浙大校赛--G--Postman(简单思维题)
一个思维水题 题目大意为,一个邮递员要投递N封信,一次从邮局来回只能投递K封.求最短的投递总距离.需注意,最后一次投递后无需返回邮局. 本题思路要点: 1.最后一次投递无需返回邮局,故最后一次投递所行 ...
- Codeforces 515C 题解(贪心+数论)(思维题)
题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...
- Codeforces 1188B - Count Pairs(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...
随机推荐
- 浅出讲解:php的socket通信
原文地址:https://www.cnblogs.com/aipiaoborensheng/p/6708963.html 对TCP/IP.UDP.Socket编程这些词你不会很陌生吧?随着网络技术的发 ...
- react做的react-redux购物车
### 1. 创建项目 create - react - app 项目名(shop) ### 2. 进入项目,下载redux,react-redux cnpm install redux ...
- 使用kubeadm部署K8S v1.17.0集群
kubeadm部署K8S集群 安装前的准备 集群机器 172.22.34.34 K8S00 172.22.34.35 K8S01 172.22.34.36 K8S02 注意: 本文档中的 etcd . ...
- Kali中安装VMwaretools
VMware Workstation 中 虚拟机选项,安装VMware Tools 选项. 在虚拟机中,打开VMware Tools,将 VMwareTools-10.1.15-6627299.tar ...
- clog就用clog的后缀名
/tmp/log/shuanggou.clog /tmp/log/shuanggou.log /tmp/log/shuanggou_success.log /tmp/log/shuanggou_err ...
- windows使用sqlpus连接oracle 数据库
1.先安装好Instant Client程序. 2.打开cmd 执行sqlplus命令,如果出现如下图 2.说明需要把oracle install 的bin目类 添加系统环境path中,如下图添加环境 ...
- Java的设计模式(2)--单例模式
保证一个类仅有一个实例,并提供一个访问它的全局访问点. 好处: (1)频繁使用的对象,可以省略new操作花费的时间,这对于那些重量级对象而言,是非常客观的一笔开销. (2)由于new的次数 ...
- Office 2016、2019 与 Office 365 的区别
点开观看更清晰:
- laravel中间件的实现原理
中间件的实现原理 运用 array_reduce 以及 call_user_func 实现 interface Middleware { public static function handle(C ...
- linux下查看当前进程以及杀死进程
###linux下查看当前进程以及杀死进程 查看进程 ps命令查找与进程相关的PID号: ps a :显示现行终端机下的所有程序,包括其他用户的程序. ps -A :显示所有程序. ps c :列出程 ...