POJ 2443 Set Operation 题解】的更多相关文章

本文同时发布于 博客园 洛谷博客 题目链接 题目分析 给你n个集合,每个集合里面都有可能会重复的数字 q个询问,每次询问两个数是否会在同一集合内 $n<=1000$ $q<=200000$ 做法分析 算法一: $\mathcal{O}(nq)$ 的暴力做法 $vis[x][i]$ 表示 x 是否出现在第 i 个集合中,是为1,否为0 每一次询问枚举 算法二: 状态压缩压掉第二维 时间复杂度 $\mathcal{O}(n+q)$ 但是 $n<=1000$ 范围会爆空间 具体做法: vis[…
题目链接:http://poj.org/problem?id=2443 题目大意:给你N个集合,每个集合里有若干个数.M个查询,每个查询有a,b两个数.问是否存在一个集合同时包含a,b这两个数.若存在则输出Yes,否则为No. 康神竟然一下子就想出来了.. 思路:统计每个数在哪个集合出现过,用bitset记录下来.然后对于a,b,则把两个bitset取与. 如果得到空集就是No,否则就是Yes. #include <cstdio> #include <bitset> #includ…
Set Operation Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3558   Accepted: 1479 Description You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set" isn't entirely the same as the "set" defi…
http://poj.org/problem?id=2443 题意: 有1000个集合,每个集合有至多10000个数,之后输入多个询问,判断询问的两个数是否位于同一个集合. 思路: 位运算...很强大!! 用二进制来判断是否位于这个集合,0表示不在,1表示处于在的. 那么对于1000个集合来说,就需要1000位的二进制,一个int型的数可以保存32的二进制,32*32>1000,所以我们只需要32位的数组就可以表示出这1000个集合. #include<iostream> #includ…
Description You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set" isn't entirely the same as the "set" defined in mathematics, and a set may contain two same element). Every element in a set is represente…
POJ 2823 Sliding  Window 题解 Description An array of size n ≤ 106 is given to you. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the slidi…
Set Operation Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2965   Accepted: 1196 Description You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set" isn't entirely the same as the "set" defi…
链接:http://poj.org/problem?id=2585 题意: 某个人有一个屏幕大小为4*4的电脑,他很喜欢打开窗口,他肯定打开9个窗口,每个窗口大小2*2.并且每个窗口肯定在固定的位置上(见题目上的图),某些窗口可以覆盖另一些窗口(可以脑补).询问给出的电脑屏幕是否是合法的. 分析: 可以预先处理出每个格子应该有哪几个窗口在这上面,将最上面的窗口与其他窗口连边,得到一张图,用拓扑判环,因为这道题太简单了,所以我就写这么短的题解. 代码: #include<iostream> #i…
Description 未名湖附近共有N个大小湖泊L1, L2, ..., Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ i ≤ N).如果湖泊Li和Lj之间有水路相连,则青蛙Fi和Fj互称为邻居.现在已知每只青蛙的邻居数目x1, x2, ..., xn,请你给出每两个湖泊之间的相连关系. Input 第一行是测试数据的组数T(0 ≤ T ≤ 20).每组数据包括两行,第一行是整数N(2 < N < 10),第二行是N个整数,x1, x2,..., xn(0 ≤ xi ≤ N…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organi…