题意:

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 (贪心)的更多相关文章

  1. UVA-1623 Enter The Dragon (贪心)

    题目大意:有n个装满水的湖,m天.每天可能下雨也可能晴天,只要下雨就会把湖填满,若已满,则发洪水.有一台只能在晴天使用的抽水机,每次抽水只能抽一个湖,并且全部抽光.问是否存在一种使得不发洪水的抽水方案 ...

  2. Codeforces 101487E - Enter The Dragon

    101487E - Enter The Dragon 思路:做的时候两个地方理解错了,第一个事我以为龙吸了水,水就干了,其实龙是在下雨之前吸的,下雨时湖水又满了,所以湖水永远不会干:第二个是以为只要找 ...

  3. UVA - 1623 Enter The Dragon(贪心)

    题目: 思路: 读完题之后有了以下想法: 当遇到下雨的天,就找这个湖泊上一次下雨满了之后又一次不下雨的日期.有就在这个日期下记录被神龙喝干的湖的编号,没有就是不符合题意. 这个想法是对的,但是却被代码 ...

  4. UVA 1623 Enter The Dragon

    题意: 一只龙,在每个不下雨的日子都可以喝干一个湖里的水,当湖满时,再向这个湖里下雨就会溢出.给出下雨的顺序,求龙喝水的序列. 分析: 记录每个湖上次满水的日子,和不下雨的日子.下雨时,查找当前湖上次 ...

  5. C# list distinct操作

    使用代理实现对C# list distinct操作   范型在c#编程中经常使用,而经常用list 去存放实体集,因此会设计到对list的各种操作,比较常见的有对list进行排序,查找,比较,去重复. ...

  6. angr 学习笔记

    前言 angr 是一个基于 符号执行 和 模拟执行 的二进制框架,可以用在很多的场景,比如逆向分析,漏洞挖掘等.本文对他的学习做一个总结. 安装 这里介绍 ubuntu 下的安装,其他平台可以看 官方 ...

  7. Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)

    ---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...

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

  9. UVA 11292 Dragon of Loowater(简单贪心)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

随机推荐

  1. ip转十进制(PHP、MySQL)

    mysql与php中都提供了IP转换十进制数函数 1. IP 由点分格式,转换为数字格式,代码如下: mysql> select inet_aton('127.0.0.1'); +------- ...

  2. Scala与Mongodb实践3-----运算环境的搭建

    目的:使的在IDEA中编辑代码,令代码实现mongodb运算,且转换较为便捷 由实验2可知,运算环境的搭建亦需要对数据进行存储和计算,故需要实现类型转换,所以在实验2的基础上搭建环境. 由菜鸟教程可得 ...

  3. redis订阅发布简单实现

    适用场景 业务流程遇到大量异步操作,并且业务不是很复杂 业务的健壮型要求不高 对即时场景要求不高 原理介绍 redis官网文档:https://redis.io/topics/notification ...

  4. Microsoft Azure Storage Explorer(2)

    之前写过一个往Microsoft Azure Storage Explorer里存储的功能,现在又要把东西给下载下来. 记录一下: public string DownFileFromAzure() ...

  5. html5中的Web Storage

    html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage.sessionStorage用于本地存储一个会话(session)中的数据,这些数据只有 ...

  6. 替代not in 和 in 的办法

    在程序中,我们经常会习惯性的使用in和not in,在访问量比较小的时候是可以的,但是一旦数据量大了,我们就推荐使用not exists或者外连接来代替了.如果要实现一张表有而另外一张表没有的数据时, ...

  7. 在Vue+element 开发中报: The template root requires exactly one elemen 错的解决和原因

    一.我正准备使用Vue + Element进行新的项目开发,然后在进行添加下一个组件时报错  二.解决及原因: 原来template中只允许模板里存在一个根节点,在 template 中添加一个 &l ...

  8. double涉及大数据的时候会变成科学计数法

    double b=1.23456789128E8DecimalFormat df = new DecimalFormat("0.00");//精度自己控制保留几位小数点 Strin ...

  9. isinstance 和type

    推荐使用 isinstance 判断对象类型. isinstance 的用法: 语法: isinstance(object, classinfo) 其中,object 是变量,classinfo 是类 ...

  10. Python中的 if __name__ == '__main__' 是什么意思?

    最近在看Python代码的时候,因为是Python初学者,看到这个if __name__ == '__main__' 的判断,并且下面还有代码语句,看了其他地方的说明,还是没搞明白是什么意思, 在看到 ...