LA 3644 - X-Plosives ( 也即UVA 1160)】的更多相关文章

LA看题 请点击:传送门 UVA 上也有这题 :UVA 1160 - X-Plosives 题目大意就是如果车上存在 k 个简单化合物,正好包含 k 种元素 ,那么它们将有危险,此时你应该拒绝装车. 要求输出没有装车的化合物. 把每个元素看成顶点,则一个简单化合物就是一条边.如果存在环形,那么组成环的化合物是危险的,否则就是安全的. 那么如何实现呢? 用并查集. #include<cstdio> const int MAXN=100000+10; int p[MAXN]; int findse…
UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r++; printf("Case %d: %d\n",++kas,r); } ; } LA 3602 DNA Consensus String 贪心构造,每一位上选出现次数最多的. #include<bits/stdc++.h> using namespace std; ,ma…
X-Plosives A secret service developed a new kind ofexplosive that attain its volatile property only when a specific association ofproducts occurs. Each product is a mix of two different simple compounds, towhich we call abinding pair. If N>2, thenmix…
题目传送门 题意:训练指南P191 分析:本题特殊,n个物品,n种元素则会爆炸,可以转移到图论里的n个点,连一条边表示u,v元素放在一起,如果不出现环,一定是n点,n-1条边,所以如果两个元素在同一个集合就会爆炸. #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct DSU { int rt[N], rk[N]; void init(void) { memset (rt, -1, sizeof…
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1645 题意:有一些化合物,每种化合物中含有两种元素,如果有k种化合物含有K种元素就会爆炸,现在装车司机按照输入顺序一件一件的装,遇到加入后会爆炸的化合物就不装,问会有多少化合物不能被装入. 解法:将每种元素看成一个顶点,一个化合物含有两种元素就是一条边,构图完成后…
最简单的并查集 多做做水题,加深一下理解 //#define LOCAL #include <cstdio> + ; int parent[maxn]; int GetParent(int a) { return parent[a] == a ? a : parent[a] = GetParent(parent[a]); } int main(void) { #ifdef LOCAL freopen("3644in.txt", "r", stdin);…
题意是一次装入物品,物品由两种元素组成,当遇到即将装入的物品与已经装入的物品形成k个物品,k种元素,跳过该物品的装入.可以将每种元素看成顶点,物品看成一条边.这样问题就转化为利用并查集求环的情况. 算法竞赛训练指南中的代码: #include <iostream> #include <cstdio> #include <climits> #include <cstring> #include <cstdlib> #include <cmat…
A secret service developed a new kind of explosive that attain its volatile property only when a specicassociation of products occurs. Each product is a mix of two different simple compounds, to which wecall a binding pair. If N > 2, then mixing N diff…
https://vjudge.net/problem/UVALive-3644 简单的并查集题目. #include<iostream> using namespace std; + ; int p[maxn]; int find(int x) { return p[x] != x ? p[x] = (find(p[x])) : x; } int main() { //freopen("D:\\txt.txt", "r", stdin); int x,…
A secret service developed a new kind of explosive that attain its volatile property only when a specific association of products occurs. Each product is a mix of two different simple compounds, to which we call a binding pair. If N > 2, then mixing N…
题目大意:有一些简单的化合物,每个化合物由两种元素组成,把这些化合物按顺序装车,若k个化合物正好包含k种元素,那么就会爆炸.避免爆炸,有些化合物就不能装车.求有多少个不能装车. 题目分析:若k个化合物正好包含k种元素,那么就会爆炸.我们把每种元素看成一个顶点,每种化合物看成一条边,若有环存在的时候正好是爆炸的情况,所以避免成环记录不能放的数量就行了. #include<iostream> #include<cstdio> using namespace std; ; int f[m…
A secret service developed a new kind of explosive that attain its volatile property only when a specific association of products occurs. Each product is a mix of two different simple compounds, to which we call a binding pair. If N > 2, then mixing…
在网上总是查不到很系统的练ACM需要学习的数据结构资料,于是参考看过的东西,自己整理了一份. 能力有限,欢迎大家指正补充. 分类主要参考<算法竞赛入门经典训练指南>(刘汝佳),山东大学数据结构模板 ⊙基本数据结构 1.链表: 块状链表:没练过 Dancing Links:用于优化搜索.解决精确覆盖问题和重复覆盖问题的利器. Knuth教授的始祖论文:Dancing Links中文版 Dancing Links介绍(这篇对DLX的工作过程演示的很详细) DLX——Dancing Links(这篇…
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <queue> #include <map> #include <set> #include <ctime> #include <cm…
option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosmsg=Submission+received+with+ID+1708713">https://icpcarchive.ecs.baylor.edu/index.php? option=com_onlinejudge&Itemid=8&page=show_problem&…
LA 3641 Leonardo的笔记本 题目 给出26个大写字母的置换B,问是否存在要给置换A,使得 \(A^2 = B\) 分析 将A分解为几个循环,可以观察经过乘积运算得到\(A^2\)后,循环有什么不同.将循环画成一个环,给他们标号\(0,1,\cdots,n-1\), 0号指向1号,n-1号指向1号.如果 n 是奇数,那么可以发现\(A^2\)中,0号指向了2号,2号指向了4号...n-1号指向了1号,1号指向3号...n-2号指向0号,他们依然是一个环.但是如果 n 是偶数,那么0号…
https://vjudge.net/problem/UVA-1401 题意 给出S个不同的单词作为字典,还有一个长度最长为3e5的字符串.求有多少种方案可以把这个字符串分解为字典中的单词. 分析 首先强烈吐槽,vjudge上的UVALive 3942怎么都过不了...然而题目一模一样的UVA 1401就稳稳地过了...很玄学. 根据题意可以想到一个dp,dp[i]表示从第i个字符开始的字符串的分解方案.那么dp[i]=dp[i]+dp[i+len(x)],其中单词x为匹配的前缀. 如此,从后开…
算法入门经典训练指南88页练习 ::这道题只要把原矩阵扩大4倍,那么其跟最大子矩阵的题目就很类似,把二维转化成一维,求最大的序列和,不过这个序列的长度不能超过n. 长度不能超过n? 那这道题又跟hdu 3415 HDU 3415 Max Sum of Max-K-sub-sequence (单调队列) #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #…
Pie My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one p…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2637 题意 积木,有左视图和前视图,问最少几块积木 思路 明显,把前视图视作列,左视图视作行,从大到小排列行和列,如果此时未处理的行列最大值恰巧相等为h,那么就是说在这个新行/列中,恰可以放一个高为h的积木.如果不相等且较大值为h,那么就必须要做一个高为h的积木组,假如…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2095 题意 球赛,n个球队,每两个之间赛两场,胜得三分,平得1分.梦之队是胜利场数最多的队伍,问梦之队的最低排名. 思路 明显,可以令梦队和其他队伍都相差1个胜局. 那么不妨干脆设梦队胜局为2,其他队伍胜局数为1 由于每个队伍只能参与2n-2场比赛,让情况尽可能对梦队不…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1267 题意 田忌赛马,问最多能赢到多少钱?每局200元 思路 明显,把田忌的赛马排列一下,从速度高到低,齐王的也从高到低排列,当前田忌最高的赛马无法处理齐王最高的赛马,则换成田忌最慢的赛马去碰瓷. 难在如何处理平局-也就是速度相同的赛马. 有的时候本可以平局,但是最好先…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2255 题意 n个任务,允许时间区间为[ri, di](ri , di <= 20000),运算量为wi,可以分割,问最小运算速度 思路 明显,应该二分枚举最小运算速度, 对于时刻i来说,应该优先处理已经开始的最早结束的任务.接着,如果任务已经处理完毕,那就应该等待…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1214 题意 问字符串a能否是字符串b经过某种替换+移位密码的密文 思路 明显,计数对的上就行 刘书题目描述不全面 代码 #include <algorithm> #include <cassert> #include <cmath>…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1984 题意 按顺序给出平面n个点,每个点上都有重物,一次只能按顺序拿重量不超过c的重物,从原点出发并且返回原点,问至少多少次能把全部重物拿回原点 思路 明显,令dp[i]为从1拿到i所需的最小出发次数,令dist0[i]为从原点到i的距离,令dist[i]为从i到i-1…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1883 题意 共有n个数(1..n)围成一个首尾相接的环,从m开始删除,每隔k个删除,最后留下来的是几? 思路 如刘书,首先是要找到递推关系. 1. 把起点视作编号0,f[n]为还剩下n个数(编号当然是紧挨的)的时候留下的最后一个编号,那么,明显f[n]与f[n - 1]…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=966 题意 n个大写字母串(n <= 24),问最多取多少个,使得所有字符出现的次数都是偶数. 思路 如刘书 1. 由于最多出现26个字母,而且字母在字符串中出现的次数本身不重要,只要记录奇偶性,所以可以将这些字符串转化为01串便于存储. 2. 问题转化为最多取多少…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1696 题意 平面上有n个整数点,找一个矩形,使得边界上包含尽量多的点. 思路 如刘书 首先可以按照x对所有点排序,然后枚举矩形左右边界 确定左右边界之后,接下来就可以枚举下边界,直接求最优上边界. 当左右下边界确定后,就能知道图中粉色部分上有多少个点,但这样离求出带上边…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1030 题意 矩阵,有障碍和普通地面两种子元素,求普通地面连成的子矩阵面积最大值 * 3 思路 如刘书 对于子矩阵长方形来说,其底边上必然有一点,该点向上可以延伸的距离就是子矩阵的长,枚举这一点,设为(i,j).(i,j)不是障碍是普通地面. 令up[i][j]为其向上能…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1178 题意 圆桌上有n个人,每个人要求a_i种不同的礼物,相邻两个人的礼物不能重复,问有至少要准备多少种礼物 思路 如刘书 1. 明显,若n=1,直接输出a[0] 2. 若n为偶数,则可以形如ABABAB,直接取最大的两个相连之和 3. 若n为奇数,则可以转化为二分判断…