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 ...
随机推荐
- 微信小程序的页面渲染(if/for)
下面,粗略的介绍一下微信小程序的条件渲染.列表渲染.数据绑定等,详细的内容大家可以去看微信小程序的API,在此只做简单描述,希望能帮助到大家 条件渲染 <!--wxml--> <vi ...
- 电子邮件和URL输入控件
HTML5还引入了让用户输入邮箱地址和URL的输入控件.那些不支持这类输入控件的浏览器会把他们当成普通文本框来处理. <!DOCTYPE html> <!-- To change t ...
- 关于《汇编语言(王爽)》程序6.3使用16个dw 0的问题
在学习王爽老师<汇编语言>的第6.2节时,在程序6.3代码中,给出了如下的代码: assume cs:code code segment dw 0123h, 0456h, 0789h, 0 ...
- CentOS 6.8 部署django项目一
CentOS 6.8 部署django项目二 1.安装python3.5(默认是2.6) 参考:http://blog.csdn.net/shaobingj126/article/details/50 ...
- Latex 算法Algorithm
在计算机科学当中,论文当中经常需要排版算法.相信大家在读论文中也看见了很多排版精美的算法.本文就通过示例来简要介绍一下 algorithms 束的用法.该束主要提供了两个宏包,包含两种进行算法排版的环 ...
- 子元素应该margin-top为何会影响父元素【转】
这个问题困惑了很久,虽然没有大碍早就摸出来怎么搞定它,但始终不明白原因出在哪里,如果只是IE有问题我也不会太在意,可问题是所有上等浏览器都表现如此,这样叫我怎能安心?今天总算下狠心查出来怎么回事,居然 ...
- Java探针-Java Agent技术-阿里面试题
Java探针参考:Java探针技术在应用安全领域的新突破 最近面试阿里,面试官先是问我类加载的流程,然后问了个问题,能否在加载类的时候,对字节码进行修改 我懵逼了,答曰不知道,面试官说可以的,使用Ja ...
- MFC_CFileDialog_选择文件夹
场景 在MFC中有时候只需要选择一个文件夹而不需要选择文件,这时候可以通过下列方式来进行选择 技术点 BROWSEINFO typedef struct_browseinfo { HWND hwndO ...
- jmeter之ip欺骗
说明:我看有的博客说官方文档是在jmeter2.5以上的版本有此功能的实现~ 我的是2.13版本,也可以实现 . 准备工作: 使用IP欺骗功能必须得本地有多个可用IP,通常普通的PC机只有一个物理网卡 ...
- Coursera台大机器学习技法课程笔记07-Blending and Bagging
这一节讲如何将得到的feature或hypothesis组合起来用于预测. 1. 林老师给出了几种方法 在选择g时,需要选择一个很强的g来确保Eval最小,但如果每个g都很弱该怎么办呢 这个时候可以选 ...