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 ...
随机推荐
- Redis 千万不要乱用KEYS命令,不然会挨打的
Redis现如今使用的场景越来越多?如何批量删除key呢? 有人说用KEYS命令,刚开始学Redis的时候就是用这个命令列出库中键. KEYS命令要谨慎使用. 为何?客观别急,我们先一步步来看. KE ...
- linux下安装cmake方法(1)---下载压缩包
OpenCV 2.2以后的版本需要使用Cmake生成makefile文件,因此需要先安装cmake:还有其它一些软件都需要先安装cmake 1.在linux环境下打开网页浏览器,输入网址:http:/ ...
- 【Java基础总结】反射
1. 什么是反射 Class.Method.Field.Constructor,它们是反射对象.它们是类.方法.成员变量.构造器,在内存中的形式. 也就是万物皆对象!类是类型.方法是类型.成员变量是类 ...
- 唬人的Java泛型并不难
泛型 public interface Foo<E> {}public interface Bar<T> {}public interface Zar<?> {} ...
- cogs 1176. [郑州101中学] 月考 字典树
1176. [郑州101中学] 月考 ★★☆ 输入文件:mtest.in 输出文件:mtest.out 简单对比时间限制:1 s 内存限制:128 MB [题目描述] 在上次的月考中B ...
- 深入理解协程(四):async/await异步爬虫实战
本文目录: 同步方式爬取博客标题 async/await异步爬取博客标题 本片为深入理解协程系列文章的补充. 你将会在从本文中了解到:async/await如何运用的实际的爬虫中. 案例 从CSDN上 ...
- django 建立安全索引
上篇记录使用“CONCURRENTLY” 命令行执行不锁表索引,对于django, 如何执行呢?这里记录一种方法,修改django迁移文件. 在执行完迁移后,为了方便找到该迁移文件,可以采用指定命名迁 ...
- java 赋值运算
注意:在赋值运算的时候,会自动发生数据类型转变 例子 public class test{ public static void main(String[] args){ byte num = 5; ...
- Oracle GoldenGate Best Practices: Active-Active Configuration with DML Auto CDR
Executive Overview This document is an introduction to Oracle GoldenGate (DIPC remote agent)’s best ...
- Linux中两个重要的基础服务
本文服务器基于centos7,客户端Windows10 FTP FTP(File Transfer Protocol),文件传输协议,是一个比较古老的基于TCP,用于不同计算机间传递文件的协议. 安装 ...