Sea Battle<海战>(思路题)
来源:互联网 发布:数组去重复js 编辑:程序博客网 时间:2024/05/16 23:39
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn’t know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called “hit”) or not (this case is called “miss”).
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn’t. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
input
5 1 2 1
00100
output
2
4 2
input
13 3 2 3
1000000010001
output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the “1” character). So, it is necessary to make two shots: one at the left part, and one at the right part.
#include<queue>#include<stack>#include<vector>#include<math.h>#include<stdio.h>#include<numeric>//STL数值算法头文件#include<stdlib.h>#include<string.h>#include<iostream>#include<algorithm>#include<functional>//模板类头文件using namespace std;const int INF=1e9+7;const int maxn=201000;int main(){ int map[maxn],p[maxn]; int n,a,b,k,sum=0,ans=0; scanf("%d%d%d%d",&n,&a,&b,&k); for(int i=1; i<=n; i++) scanf("%1d",&map[i]); for(int i=1; i<=n; i++) { if(map[i]==0) { sum++; //假设b个点就有一条船 if(sum==b) { sum-=b; p[++ans]=i; //printf("p[ans]=%d \n",p[ans]); } } else //为1,则一定没有船,从0开始计数 sum=0; } //一共a条船,由于只需要打掉一条船,那么只需将可能有船的点打到只剩 (a-1) 就行了 (**ans是每b个数记一次**) printf("%d\n",ans-(a-1)); for(int i=1; i<=ans-a+1; i++) printf("%d ",p[i]); return 0;}
- Sea Battle<海战>(思路题)
- Codeforces738D-Sea Battle(贪心)
- CodeForces 729D Sea Battle(思维题)
- POJ 1856 Sea Battle(dfs)
- Codeforces #380(Div.2)D.Sea Battle【贪心】好题~
- POJ 1856 Sea Battle
- poj-1856 Sea Battle
- Codeforces Round #380 D. Sea Battle (思维题)
- Codeforces Round #380 Div. 1 B. Sea Battle(贪心)
- POJ 1856 Sea Battle(DFS)
- POJ 1856 Sea Battle(BFS).
- POJ 1856 Sea Battle(DFS)
- POJ 1856 Sea Battle 笔记
- Poj 1856 Sea Battle【Dfs+思维】
- codeforces 738D Sea Battle 思维+构造
- 【Codeforces 729D Sea Battle】+ 简单思维
- Codeforces(738D)-D. Sea Battle
- POJ 3546 Sea battle 英文少
- jdbc接口核心的API
- JS 获取当前日期时间 (如:2017-03-17 18:55:03 星期六)
- linux文件共享之samba配置
- Android中的MVC
- 正则表达式
- Sea Battle<海战>(思路题)
- android开发中防止刚进入activity时edittext获取焦点,防止自动弹出软键盘
- 把数组排成最小的数。充分利用string的自带compare
- 【USACO 2007 Open Silver】City Horizon 线段树
- 自定义两端圆角且图片为背景的进度条
- 取出ios模拟器中程序写下的文件
- linux线程互斥与同步
- 第二十二、Java之单例设计模式
- 2017.03.10【NOIP 普及组】模拟赛C组 三条直线Three lines 题解