题目链接 http://codeforces.com/contest/729/problem/D

题意:给你一个1*n的区域有a艘船,每艘船宽b,已经开了k枪都没打到,问你最少再开几枪至少能打到一艘船。

想清楚了挺简单的,只要找到所有船可能放的地方然后存下再找任意sum-a+1个位置即可。

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int M = 2e5 + 10;
char s[M];
int main()
{
int n , a , b , k;
cin >> n >> a >> b >> k;
cin >> s;
vector<int>q;
int len = strlen(s);
for(int i = 0 ; i + b - 1 < n ; ++i) {
int flag = 0;
for(int j = 0 ; j < b && i < n ; ++j , ++i) {
if(s[i] == '1') {
flag = 1;
break;
}
}
if(!flag) {
q.push_back(i - 1);
i--;
}
}
int gg = q.size() - a + 1;
cout << gg << endl;
for(int i = 0 ; i < gg ; i++) {
cout << q[i] + 1 << ' ';
}
return 0;
}

Codeforces Technocup 2017 - Elimination Round 2 D. Sea Battle(贪心)的更多相关文章

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

  2. Codeforces Technocup 2017 - Elimination Round 2 E Subordinates(贪心)

    题目链接 http://codeforces.com/contest/729/problem/E 题意:给你n个人,主管id为s,然后给你n个id,每个id上对应一个数字表示比这个人大的有几个. 最后 ...

  3. Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)

    http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...

  4. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C

    Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...

  5. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B

    Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...

  6. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A

    Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...

  7. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  8. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  9. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

随机推荐

  1. java并发程序和共享对象实用策略

    java并发程序和共享对象实用策略 在并发程序中使用和共享对象时,可以使用一些实用的策略,包括: 线程封闭 只读共享.共享的只读对象可以由多个线程并发访问,但任何线程都不能修改它.共享的只读对象包括不 ...

  2. js中slice和splice的区别

    言简意赅,直接上货. slice():该方法会返回一个新的数组,强调:新数组,并不会影响原来的数组.先来看看语法咋说:arrayObject.slice(start,end).其中,start必需,e ...

  3. JS构建多端应用

    JS构建多端应用 一,需求与介绍 1.1,介绍 1,Taro 是一套遵循 React语法规范的 多端开发 解决方案.现如今市面上端的形态多种多样,Web.React-Native.微信小程序等各种端大 ...

  4. 修改 jupyter notebook的默认文件夹位置

    安装好Anaconda 3以后,就可以使用Jupyter notebook了,但是我们打开Jupyter notebook后,发现界面是一个默认的目录,这个目录在哪里?如果想把自己写的程序文件保存在自 ...

  5. 记我的一次 Java 服务性能优化

    背景 前段时间我们的服务遇到了性能瓶颈,由于前期需求太急没有注意这方面的优化,到了要还技术债的时候就非常痛苦了. 在很低的 QPS 压力下服务器 load 就能达到 10-20,CPU 使用率 60% ...

  6. 高性能MySQL之事物

    一.概念 事务到底是什么东西呢?想必大家学习的时候也是对事务的概念很模糊的.接下来通过一个经典例子讲解事务. 银行在两个账户之间转账,从A账户转入B账户1000元,系统先减少A账户的1000元,然后再 ...

  7. [转载]ActiveMQ实现负载均衡+高可用部署方案

    转载于 http://www.open-open.com/lib/view/open1400126457817.html 一.架构和技术介绍 1.简介 ActiveMQ 是Apache出品,最流行的, ...

  8. linux100day(day3)--常用文本处理命令和vim文本编辑器

    今天,来介绍几个常用文本处理命令和vim文本编辑器 day3--常用文本处理命令和vim文本编辑器 col,用于过滤控制字符,-b过滤掉所有控制字符,这个命令并不常用,但可以使用man 命令名| co ...

  9. JS鼠标吸粉特效

    HTML <canvas id=canvas></canvas> CSS * { margin: 0; padding: 0; } html { overflow: hidde ...

  10. SAP 修改MIRO变式

    转自:http://blog.vsharing.com/SAP100/A799545.html