UVA1623-Enter The Dragon(并查集)】的更多相关文章

题目大意:有n个装满水的湖,m天.每天可能下雨也可能晴天,只要下雨就会把湖填满,若已满,则发洪水.有一台只能在晴天使用的抽水机,每次抽水只能抽一个湖,并且全部抽光.问是否存在一种使得不发洪水的抽水方案. 题目分析:贪心.贪心策略:对于每个下雨天 i ,让在这天之前的并且在第a[i]个湖上一次水满之后的一个晴天抽走第a[i]个湖中水. 代码如下: # include<iostream> # include<cstdio> # include<set> # include&…
题意: m个坑,n天,起初每个坑都是满的,每天至多有一个坑会下雨,下雨就会满,满了再下就输出no. 在没有雨的时候可以安排龙来喝水,把坑喝空,可行的话输出龙喝水的方案 思路: 边读入边操作,set保存下来所有没有雨的日子.对每一个有雨的日子,找离上一次满水的日子最近的一次没雨的日子,在这个日子喝掉这个坑,然后更新满水的日子(因为今天下了雨),然后删掉这个没雨的日子(因为一个坑只能喝一次),加入答案 代码: #include<iostream> #include<cstdio> #i…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2909    Accepted Submission(s): 1125 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, so it's too difficult for Monkey King(WuKong) to gather all of the dragon balls together. His country has N cities and there are exactly N dragon bal…
Problem UVA1623-Enter The Dragon Accept: 108  Submit: 689Time Limit: 3000 mSec Problem Description 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 la…
/* 题意:有N个城市, 每一个城市都有一个龙珠(编号与城市的编号相同),有两个操作 T A ,B 将标号为A龙珠所在城市的所有的龙珠移动到B龙珠所在城市中! 思路:并查集 (压缩路径的时候将龙珠移动的次数进行更新) */ #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #define M 10005 using namespace std; int f[M]…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3635 题意:有n个龙珠,n个城市.初始状态第i个龙珠在第i个城市里.接下来有两个操作: T A B:把A号龙珠所在的城市的所有龙珠全部转移到B城市中. Q A:查询A龙珠,要求:A龙珠所在城市,该城市龙珠数量,A移动的次数. 思路:用并查集可以轻松解决Q的前两个问题.关键在于如何统计A的移动次数,因为在T的时候是要将A所在城市的所有龙珠都要转移到B,那就要A集合里所有龙珠的移动次数都+1.假如我们在…
这道题说,在很久很久以前,有一个故事.故事的名字叫龙珠.后来,龙珠不知道出了什么问题,从7个变成了n个. 在悟空所在的国家里有n个城市,每个城市有1个龙珠,第i个城市有第i个龙珠. 然后,每经过一段时间,城市i的所有的龙珠都会被转移到城市j中. 现在有两种操作: 1. T A B,表示将A龙珠所在城市的所有龙珠全部转移到B龙珠所在城市去. 2. Q A,表示询问A龙珠所在的城市X,以及X城市有几个龙珠,A龙珠被转移了几次. 输入: 第一行输入1个整型数字t,表示一共t组测试样例. 接下来,每组样…
Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42416   Accepted: 13045 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Drago…
传送门 Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42463   Accepted: 13065 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang D…