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 ...
随机推荐
- js计算数字长度
js调用toString方法转为字符串后取长度 var num = 123; alert(num.toString().length);
- MySQL中查询行数最多的表并且排序
#切换到schema use information_schema; #查询数据量最大的30张表 并排序 select table_name,table_rows from tables order ...
- Go 语言读书笔记
Go语言的设计理念很明确,就是将动态类型语言的编程容易度和静态类型语言的安全效率结合起来. Go语言,又称Golang,是Google开发的一款静态强类型.编译型.并发型,并具有垃圾回收机制的 ...
- ubuntu12.04+cuda6.0+caffe(新版)的安装
参照两位的博客 http://caffe.berkeleyvision.org/ 官网 http://blog.csdn.net/u013476464/article/details/38071 ...
- VGG 参数分析 转
上面放了一个keras用vgg16训练测试的例子,我也试过用vgg16训练然后测试自己的例子,效果一般,这里我们来分析一下vgg16的网络结果 keras代码如下 def VGG_16(weights ...
- java工程师之旅-一个月工作心得
不知不觉,在工作中已经度过一个月,距离上次写文章已经好几个月了,正好还有二十分钟下班,抽点时间来写一下博文,写一下心得. 首先说一下,在我工作之前,做了一个项目,和一个外校大四的学生做一个毕业设计,一 ...
- freeRTOS中文实用教程2--队列
1.前言 freeRTOS中所有任务的通信和同步机制都是基于队列来实现. 2.队列的特点 图 队列的读写操作 队列的数据存储 (1)队列可以保存有限个具有确定长度的数据单元,队列可以保存的最大单元数目 ...
- MySQL版本升级参考资料【转】
MySQL升级参考资料 MySQL 升级的最佳实践 - 技术翻译 - 开源中国社区https://www.oschina.net/translate/mysql-upgrade-best-practi ...
- 调用链系列一、Zipkin架构介绍、Springboot集承(springmvc,HttpClient)调用链跟踪、Zipkin UI详解
1.Zipkin是什么 Zipkin分布式跟踪系统:它可以帮助收集时间数据,解决在microservice架构下的延迟问题:它管理这些数据的收集和查找:Zipkin的设计是基于谷歌的Google Da ...
- oracle move 释放 表空间
使用sqlplus 操作 alter table TEST_TB1 move storage(initial 64K); alter table TEST_TB1 move ; select SEG ...