UVA1623 Enter The Dragon (贪心)
题意:
m个坑,n天,起初每个坑都是满的,每天至多有一个坑会下雨,下雨就会满,满了再下就输出no。
在没有雨的时候可以安排龙来喝水,把坑喝空,可行的话输出龙喝水的方案
思路:
边读入边操作,set保存下来所有没有雨的日子。对每一个有雨的日子,找离上一次满水的日子最近的一次没雨的日子,在这个日子喝掉这个坑,然后更新满水的日子(因为今天下了雨),然后删掉这个没雨的日子(因为一个坑只能喝一次),加入答案
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int n;
int vis[maxn];
int pre[maxn];
int ans[maxn];
set<int>norain;
int main() {
int T;
scanf("%d", &T);
int top; while(T--){
int m, n;
scanf("%d %d", &m, &n);
int flg = ;
mem(ans, );
mem(vis, );
norain.clear();
mem(pre, );
//int p = 0;
for(int i = ; i < n; i++){
int c;
scanf("%d", &c);
if(!flg)continue;
if(c==){
norain.insert(i);
vis[i] = ;
}
else{
set<int>::iterator it = norain.lower_bound(pre[c]);
if(it == norain.end()){
flg = ;
continue;
} ans[*it] = c;
//printf(" %d\n", *it);
norain.erase(it);
pre[c] = i;
}
//printf("%d ", ans[i]); }
if(!flg){
printf("NO\n");
}
else{
printf("YES\n");
for(int i = ; i < n; i++){
if(vis[i])printf("%d ", ans[i]);
}printf("\n");
}
}
return ;
}
/*
4
2 4
0 0 1 1
2 4
0 1 0 2
2 3
0 1 2
2 4
0 0 0 1
*/
UVA1623 Enter The Dragon (贪心)的更多相关文章
- UVA-1623 Enter The Dragon (贪心)
题目大意:有n个装满水的湖,m天.每天可能下雨也可能晴天,只要下雨就会把湖填满,若已满,则发洪水.有一台只能在晴天使用的抽水机,每次抽水只能抽一个湖,并且全部抽光.问是否存在一种使得不发洪水的抽水方案 ...
- Codeforces 101487E - Enter The Dragon
101487E - Enter The Dragon 思路:做的时候两个地方理解错了,第一个事我以为龙吸了水,水就干了,其实龙是在下雨之前吸的,下雨时湖水又满了,所以湖水永远不会干:第二个是以为只要找 ...
- UVA - 1623 Enter The Dragon(贪心)
题目: 思路: 读完题之后有了以下想法: 当遇到下雨的天,就找这个湖泊上一次下雨满了之后又一次不下雨的日期.有就在这个日期下记录被神龙喝干的湖的编号,没有就是不符合题意. 这个想法是对的,但是却被代码 ...
- UVA 1623 Enter The Dragon
题意: 一只龙,在每个不下雨的日子都可以喝干一个湖里的水,当湖满时,再向这个湖里下雨就会溢出.给出下雨的顺序,求龙喝水的序列. 分析: 记录每个湖上次满水的日子,和不下雨的日子.下雨时,查找当前湖上次 ...
- C# list distinct操作
使用代理实现对C# list distinct操作 范型在c#编程中经常使用,而经常用list 去存放实体集,因此会设计到对list的各种操作,比较常见的有对list进行排序,查找,比较,去重复. ...
- angr 学习笔记
前言 angr 是一个基于 符号执行 和 模拟执行 的二进制框架,可以用在很多的场景,比如逆向分析,漏洞挖掘等.本文对他的学习做一个总结. 安装 这里介绍 ubuntu 下的安装,其他平台可以看 官方 ...
- Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)
---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...
- [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shor ...
- UVA 11292 Dragon of Loowater(简单贪心)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
随机推荐
- 22.Python安装和卸载第三方模块方法
安装和卸载第三方开源模块的步骤:下例,安装urllib3模块的步骤. 1.安装开源模块步骤: 按键盘windows键+r键,输出cmd回车.或开始->windows系统->命令提示符: 输 ...
- AQS原理及应用
To use this class as the basis of a synchronizer, redefine the * following methods, as applicable, b ...
- Linux磁盘管理之LVM逻辑卷快照
一.快照的工作原理 所谓快照就是将当时的系统数据记录下来,在未来若有数据变动,则会将变更前的数据放入快照区进行保存.我们可理解为快照就是给系统拍了一张照片,记录当时系统在拍快照的状态.只不过现实生活中 ...
- 更加清晰的TFRecord格式数据生成及读取
TFRecords 格式数据文件处理流程 TFRecords 文件包含了 tf.train.Example 协议缓冲区(protocol buffer),协议缓冲区包含了特征 Features.Ten ...
- 《Java核心技术》 JVM指令集
https://www.jianshu.com/p/bc91c6b46d7b
- 【 Tomcat 】tomcat8.0 基本参数调优配置-----(1)
Tomcat 的缺省配置是不能稳定长期运行的,也就是不适合生产环境,它会死机,让你不断重新启动,甚至在午夜时分唤醒你.对于操作系统优化来说,是尽可能的增大可使用的内存容量.提高CPU 的频率,保证文件 ...
- angularjs路由菜单强制刷新
在开发过程中遇到使用路由控制单页加载页面时,点击菜单页面不重新刷新的情况,angularjs认为路由没有变化,而不会去刷新页面,解决办法: angular.module('myApp').direct ...
- [bzoj1041] [洛谷P2508] [HAOI2008] 圆上的整点
Description 求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数. Input 只有一个正整数n,n<=2000 000 000 Output 整点个数 Samp ...
- [洛谷P1606] [USACO07FEB] 荷叶塘Lilypad Pond
Description 为了让奶牛们娱乐和锻炼,农夫约翰建造了一个美丽的池塘.这个长方形的池子被分成了M行N列个方格(1≤M,N≤30).一些格子是坚固得令人惊讶的莲花,还有一些格子是岩石,其余的只是 ...
- [bzoj2326] [洛谷P3216] [HNOI2011] 数学作业
想法 最初的想法就是记录当前 \(%m\) 值为cur,到下一个数时 \(cur=cur \times 10^x + i\) n这么大,那就矩阵乘法呗. 矩阵乘法使用的要点就是有一个转移矩阵会不停的用 ...