CF 738D 贪心
来源:互联网 发布:机器人仿真软件 编辑:程序博客网 时间:2024/05/16 06:07
http://codeforces.com/contest/738/problem/D
题意:小时候玩的潜艇游戏,只不过题目是在一维上面,已知有一些长度为L的潜艇,玩家已经侦测了一些位置但是没有发现潜艇,问题是玩家再侦测那些位置可以确保发现潜艇。
思路:贪心取就好,首先把可能有潜艇的区间拿出来(长度大于等于L的),然后对于这些区间每隔L就取一个,并且可能放的最多的潜艇-1,重复上述过程,直到不能再将m个潜艇放在剩下的位置,那么就确保一定发现了潜艇。。。
代码:
#include <bits/stdc++.h>using namespace std;int n,a,b,k;string s;vector<pair<int,int> > v;vector<int> ans;int main(){ cin>>n>>a>>b>>k>>s; int tot=0,be=0; int sum=0; for(int i=0;i<s.size();i++){ if(s[i]=='0'){ tot++; } else{ sum+=tot/b; if(tot>=b) v.push_back(make_pair(tot,be)); tot=0; be=i+1; } } if(s[s.size()-1]=='0'){ sum+=tot/b; if(tot>=b) v.push_back(make_pair(tot,be)); } for(int i=0;i<v.size();i++){ if(sum<a) break; int x=v[i].first; int be=v[i].second; int ll=be+x; //cout<<"B"<<be<<" "<<be+x<<endl; while(be+b<=ll){ ans.push_back(be+b); be=be+b; sum--; if(sum<a) break; } } printf("%d\n",ans.size()); for(int i=0;i<ans.size();i++){ printf("%d ",ans[i]); } return 0;}
0 0
- CF 738D 贪心
- CF 402-D 贪心
- CF 721D贪心
- CF 748D 贪心
- CF 190div2 D(贪心)
- CF 515D 图,贪心
- CF 593D LCA,贪心
- CF-45D. Event Dates(贪心)
- CF D. Population Size(贪心+模拟)
- CF#310 div2 D set+pair+贪心
- cf#310-D. Case of Fugitive-贪心
- CF 637D. Running with Obstacles 贪心
- cf 721 d(优先队列+贪心)
- CF 754D 贪心 + 优先队列
- cf 729D Sea Battle 【模拟,贪心】
- CF 363D. Renting Bikes 贪心+二分
- (贪心)【CF 893D】Credit Card
- CF 215D 贪心 交罚金的问题
- 对话框使用ocx控件封装为dll
- c语言之左右法则
- Mybatis手写分页,非常灵活
- pog 2891 Strange Way to Express Integers (中国剩余定理 非互质)
- 【爬坑之路】--Native method not found...【android studio上】
- CF 738D 贪心
- poj 1733 Parity game 离散化+带权并查集(区间)
- hive 数据倾斜总结
- 正则表达式学习
- 5、RxJava学习记录
- redis乐观锁(适用于秒杀系统)
- Javascript的内存管理
- 操作系统实验四:独占设备的静态分配模拟
- STM32 GPIO I/O复用和映射