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 ...
随机推荐
- UDP网络程序,客户端和服务端交互原理
创建一个udp客户端程序的流程是简单,具体步骤如下: 创建客户端套接字 发送/接收数据 关闭套接字 UDP是面向无连接的通讯协议,UDP数据包括目的端口号和源端口号信息,由于通讯不需要连接,所以可以实 ...
- mysql 显示表字段及mysql系统信息
参考链接: http://www.cnblogs.com/zhwl/archive/2012/08/28/2660532.html SHOW DATABASES ...
- keepalived高可用系列~通用基础
简介:今天咱们来聊聊keepalived一 keepalived 架构 1 标准架构: keepalived+lvs/haproxy+后端 real server(mysql从库,nginx.myc ...
- 用Quartz 2D画小黄人
第一步: 先创建一个OneView类,并在storyboard里边拖拽一个UIview,将这个UIview的类改成OneView.如图所示: 第二步: 在新创建的Oneview里,补齐下列代码: // ...
- pl/sql Devloper 关键字转为大写
英文版: peferences-editor-keyword case -uppercase 中文版:
- octomap 安装使用
由于工程实践中需要对机器人地图进行概率化估计并表示,故引入OctoMap库. 本文将介绍如何在Ubuntu环境下安装OctoMap. 如果你安装了ROS,那么一下的安装过程很可能会出错. 首先应该检查 ...
- 理解 Linux 配置文件【转】
转自:http://www.ibm.com/developerworks/cn/linux/management/configuration/ 分类和使用 本文说明了 Linux 系统的配置文件,在多 ...
- 源码编译安装nginx1.4.7
传统上基于进程或线程模型架构的web服务通过每进程或每线程处理并发连接请求,这势必会在网络和I/O操作时产生阻塞,其另一个必然结果则是对内存或CPU的利用率低下.生成一个新的进程/线程需要事先备好其运 ...
- 关于ajax请求,返回json数据格式
使用servlet测试 后台数据为:返回类型没有设置(方式一) String str = "["+ "{ id:1, pId:0, name:\"可折腾的父节点 ...
- JOptionPane类提示框常用方法总结
JOptionPane类封装了很多的方法,总结如下: 1.showMessageDialog 显示一个带有OK 按钮的模态对话框. 下面是几个使用showMessageDialog 的例子: Java ...