题意:

有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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  5. 【42.86%】【Codeforces Round #380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 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 ...

  7. 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 ...

  8. Sea Battle

    Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. Sea Battle<海战>(思路题)

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. 第4月第10天 iOS项目 mvc

    1. 一个uiviewcontroller发送网络请求,解析数据后放在数组里.如果是多个网络请求,就要多个成员变量存储.那是不是可以单独出一个model来解析数据,存储数据呢. 如果有一个Reques ...

  2. Android五种数据存储方式

    android 五种数据存储 :SharePreferences.SQLite.Contert Provider.File.网络存储 Android系统提供了四种存储数据方式.分别为:SharePre ...

  3. pandas 定位 loc,iloc,ix

    In [114]: df Out[114]: A B C D 2018-06-30 0.318501 0.613145 0.485612 0.918663 2018-07-31 0.614796 0. ...

  4. python中datetime与string的相互转换

    >>> import datetime >>> value = '2016-10-30 01:48:31' >>> datetime.strpti ...

  5. python3之Django多数据库

    1.定义数据库 在django项目中, 一个工程中存在多个APP应用很常见:有时候希望不同的APP连接不同的数据库,这个时候需要建立多个数据库连接.在Django的setting中使用DATABASE ...

  6. python学习:绝对路径和相对路径

    python学习:绝对路径和相对路径 大牛们应该对路径都很了解了,这篇文章主要给像我这样的入门小白普及常识用的,啊哈 下面的路径介绍针对windows,其他平台的暂时不是很了解. 在编写的py文件中打 ...

  7. java中printf()方法简单用法

    %n 换行 相当于 \n %c 单个字符 %d 十进制整数 %u 无符号十进制数 %f 十进制浮点数 %o 八进制数 %x 十六进制数 %s 字符串 %% 输出百分号 > 在printf()方法 ...

  8. 关于nginx报错/usr/share/nginx/html/jiankongshare" failed (2: No such file or directory)的问题解决

    nginx的location虚拟目录配置: monitor.conf server {       server_name   monitor.chinasoft.com;       server_ ...

  9. PYTHON-组合 封装 多态 property装饰器

    # 组合'''软件重用的重要方式除了继承之外还有另外一种方式,即:组合组合指的是,在一个类中以另外一个类的对象作为数据属性,称为类的组合 1. 什么是组合 一个对象的属性是来自于另外一个类的对象,称之 ...

  10. 设置滚动条scrolltop

    scrolltop用来设置页面的滚动条的位置 兼容性:链接 $().scrolltop(值)