Sea Battle CodeForces - 729D
题意:
有n个格子,a条船,每条船占b个格子。事先已经射击了k个格子,且这k次射击不会射到船上,求再射击几次可以射到某一条船的某一部分
思路:
观察样例可以发现,如果五个0,船的长度是3,那么这五个0中可能有
1 2 3
2 3 4
3 4 5
这三种位置都包含3这个id,所以,我们只需要射击到3这个位置就可以射击到船的某一部分
所以,我们只需要统计有多少个连续的0,就可以得到这连续的0中可能包含的船的条数,进而计算出最少的射击次数,也就是0的个数除以船的长度。
得到了总的设计次数,将其减去船的个数,便可以得到多余的射击次数,也就是说,五次射击,三条船,那么你在射击两次之后一定能射击到船的某一部分,所以最终答案就是
将其+1。那么这题就解决了,我们最后所要做的只不过是记录射击的位置,任意输出即可!
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std;
#define maxn 200000+10
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define clr(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
#define pii pair<int,int>
#define mp make_pair
#define FI first
#define SE second
#define IT iterator
#define PB push_back
#define Times 10 typedef long long ll;
typedef unsigned long long ull;
typedef long double ld; const double eps = 1e-;
const double pi = acos(-1.0);
const ll mod = (1e9+);
const int inf = 0x3f3f3f3f;
const ll INF = (ll)1e18+; using namespace std; int main(){
int n, num, len, k;
cin >> n >> num >> len >> k;
string s;
cin >> s;
vector <int > id;
int sum = ;
for (int i = ; i < s.length();){
//char c = s[i];
if (s[i] == ''){
i ++ ;
continue;
}
int length = ;
while(s[i] == ''){
length++;
i++;
if ( length % len == ){
id.push_back( i );
}
}
sum += length/len;
length = ;
//cout << "++++" <<endl;
}
//cout << sum << endl;
int answer = sum - num + ;
cout << answer <<endl;
//cout << answer <<endl;
int flag = ;
for (int i = ; i < answer; i ++){
if (!flag){
cout << id[i];
flag = ;
}
else {
cout << " " << id[i] ;
}
}
cout << endl;
}
Sea Battle CodeForces - 729D的更多相关文章
- 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 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 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- 【42.86%】【Codeforces Round #380D】Sea Battle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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 ...
- 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 ...
- Sea Battle
Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Sea Battle<海战>(思路题)
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- 自定义滤镜 ColorMatrixFilter
var url:URLRequest = new URLRequest("Koala.jpg"); var l:Loader = new Loader(); l.contentLo ...
- CentOS6.8安装配置sonarqube6.4
下载最新版本的sonar(现在改名叫sonarqube) https://www.sonarqube.org/downloads/ 我下载的版本是Sonarqube6.4 1 使用前需要 ...
- jQuery - 几种异步提交方式
$.post(url,params,callback); $.post("${ctx}/role/grant", {userId : $("#userId"). ...
- python - class类(归一化设计)
归一化设计 #继承同时具有两种含义 # 1.继承基类的方法,并且做出自己的改变或者扩展 # 2.声明某个子类兼容于某个基类,定义一个接口类,子类继承接口类,并且实现接口中定义的方法. # 实践中,继承 ...
- MHL技术剖析,比HDMI更强【转】
转自:http://blog.chinaunix.net/uid-22030783-id-3294750.html MHL这个只是经常听说,没有见过的东西,现在已经非常火热了,我们才刚刚开始做,人家三 ...
- c# webbrowser控件内核版本强制修改
int BrowserVer, RegVal; // get the installed IE version using (WebBrowser Wb = new WebBrowser()) Bro ...
- sqlserver 无法获得数据库独占权
ALTER DATABASE trqxs_cs SET OFFLINE WITH ROLLBACK IMMEDIATE
- 判断Javascript变量是否为空 undefined 或者null(附样例)
1.变量申明未赋值 var type; //type 变量未赋值 1. type==undefined //true 2. type===undefined //true 3. typeof(type ...
- MySQL双版本共存解决方案
案例是MySQL5.5(3306端口)和MySQL5.6(3307端口). 1. 修改C:\Program Files (x86)\MySQL\MySQL Server 5.6\下的my-xxx.in ...
- viewpager显示图片的Adapter
package com.ming.chiye.yishanghorse.Adapter; import android.content.Context; import android.graphics ...