UVa 1623 Enter The Dragon

本文深入探讨了信息技术领域的多个细分技术领域,包括前端开发、后端开发、移动开发等,提供了关于大数据开发、AI音视频处理、嵌入式硬件、测试、DevOps等领域的详细解析与应用实例。此外,还涵盖了操作系统、云计算、自然语言处理、区块链、隐私计算等前沿技术,以及项目管理、文档协作、版本控制等实践应用。

The capital of Ardenia is surrounded by several lakes, and each of them is initially full of water. Currently, heavy rainfalls are expected over the land. Such a rain falls to one of the lakes: if the lake is dry and empty, then it will be filled with water; if the lake is already full, then it will overflow, which will result in a natural disaster. Fortunately, the citizens have a dragon at their disposal (and they will not hesitate to use it). The dragon may drink the whole water from a lake in one sitting. Also, the mages of Ardenia already predicted the weather conditions for the next couple of years. The only question is: from which lake and when should the dragon drink to prevent a catastrophe?

Input 

The input contains several test cases. The first line of the input contains a positive integer Z$ \le$40, denoting the number of test cases. ThenZ test cases follow, each conforming to the format described below.

The first line of the input instance contains two space-separated positive integers n$ \le$106 and m$ \le$106 , where n is the number of lakes. (There are at most 10 input instances for which n$ \ge$105 or m$ \ge$105.) The second line contains the weather forecast for the next m days: mspace-separated integers t1t2,..., tm (ti $ \in$ [0, n]). If ti $ \in$ [1, n], it means a heavy rainfall over lake ti at day i. If ti = 0, there is no rain at day i, and the dragon has the time to drink the water from one lake of your choice. Note that the dragon does not drink on a rainy day.

Output 

For each test case, your program has to write an output conforming to the format described below.

In the first line your program should output word `YES' if it is possible to prevent a catastrophic overflow and `NO' otherwise. In the former case, you should output the second line containing l integers from the range [0, n], where l is the number of zeros in the weather forecast description, i.e., the number of non-rainy days. Each of these integers denotes the number of the lake from which the dragon should drink; zero means the dragon should not drink from any lake (this might be necessary, as even the dragon cannot drink from an empty lake).

Sample Input 

4 
2 4 
0 0 1 1
2 4 
0 1 0 2
2 3 
0 1 2 
2 4 
0 0 0 1

Sample Output 

NO 
YES 
1 2 
NO 
YES 
0 1 0

#include <cstdio>
#include <set>
#include <cstring>
using namespace std;
int drink[1000010];

int water[1000010];

// 代表这次下雨已经喝过
int flag[1000010];

int lasttime[1000010];

typedef struct node
{
	int num;
	int last_time;
	int place;
	bool operator < (const struct node&x) const
	{
		return last_time < x.last_time || (last_time == x.last_time && place < x.place);
	} 
}node;

node array[1000010];

set<int> d;
int main()
{
	int Z;
	scanf("%d", &Z);
	int count = 0;
	while(count < Z)
	{
		int n, m;
		scanf("%d%d", &n, &m);
		// 读入情况
        	memset(drink, 0, sizeof(drink));
        	memset(lasttime, 0, sizeof(lasttime));
		d.clear();
		int false_flag = 0;
		for(int i = 0; i < m; i++)
		{
			scanf("%d", &water[i]);
			if(false_flag)
				continue;
			if(water[i] == 0)
				d.insert(i);
			else
			{
				set<int>::iterator p = d.lower_bound(lasttime[water[i]]);
				if(p == d.end())
					false_flag = 1;
				else
				{
					drink[*p] = water[i];
					lasttime[water[i]] = i;
					d.erase(*p);
				}	
			}	
/*			if(flag[water[i]] == 0)
			{	
				flag[water[i]] = i;
				lasttime[i] = -1;
			}
			else
			{
				lasttime[i] = flag[water[i]];
				flag[water[i]] = i;
			}
			if(water[i] != 0)
			{
				array[rain_num].num = water[i];
				array[rain_num].last_time = lasttime[i];
				array[rain_num].place = i;
				rain_num++;
			}	
*/		}	
/*
		for(int i = 0; i < n; i++)
			flag[i] = 0;
*/
	/*
		int i;
		for(i = 0; i < m; i++)
		{
			if(water[i] != 0)
			{
				int j;
				int find_flag = 0;
				for(j = lasttime[i]+1; j < i; j++)
				{
					if(water[j] == 0 && drink[j] == 0)
					{
						drink[j] = water[i];
						find_flag = 1;
						break;
					}
				}
				if(!find_flag)
					break;
			}
		}		
*/
	/*
		sort(array, array+rain_num);
		int begin = 0;
		for(int i = 0; i < m; i++)
		{
			if(water[i] == 0)
			{
				if(begin < rain_num)
				{
					if(array[begin].last_time < i)
					{
						drink[i] = array[begin].num;
						begin++;
					}
				}
			}
		}	
*/
		if(false_flag)
                        printf("NO\n");
                else
                {
                        printf("YES");
                        int first_time = 1;
                        for(int i = 0; i < m; i++)
                        {
                                if(water[i] == 0)
                                {
                                        if(first_time)
                                        {
                                                printf("\n%d", drink[i]);
                                                first_time = 0;
                                        }
                                        else
                                                printf(" %d", drink[i]);
                                }
                        }
                        printf("\n");
                }
/*
		int empty_p = m-1;	
		int false_flag = 0;
		for(int i = m-1; i >= 0; i--)
		{
			// 为该下雨天找一个能喝的天
			if(water[i] != 0)
			{
//				empty_p--;
				if(empty_p >= i)
					empty_p = i-1;	
				while(empty_p >= 0)
				{
					if(water[empty_p] == water[i])
					{
						false_flag = 1;
						break;		
					}
					else if(water[empty_p] == 0)
					{
						drink[empty_p] = water[i];
						break;
					}
					empty_p--;	
				}
				if(empty_p < 0 || false_flag)
				{
					false_flag = 1;
					break;
				}
				else
					empty_p--;		
			}			
		}

		if(false_flag)
			printf("NO\n");
		else
		{
			printf("YES\n");
			int first_time = 1;
			for(int i = 0; i < m; i++)
			{
				if(water[i] == 0)
				{
					if(first_time)
					{
						printf("%d", drink[i]);
						first_time = 0;
					}
					else
						printf(" %d", drink[i]);
				}	
			}
			printf("\n");	
		}
*/		count++;	
	}		
	return 0;
}

这个题一开始想错了,应该是每个下雨的日子距离上次该湖下雨以后取一个最近的不下雨日子。
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值