POJ1733】的更多相关文章

http://poj.org/problem?id=1733 (题目链接) 题意 一个由0,1组成的序列,每次给出一段区间的奇偶,问哪一条信息不合法. Solution 并查集. 题目中序列的长度有很大,单纯搜索一定会TLE. 我们用s[i]表示前i个数的前缀和,那么a b even意味着s[b]和s[a-1]的奇偶性相同.a b odd意味着s[b]与s[a-1]的奇偶性不同.于是我们根据奇偶性的不同,用并查集依次处理他们之间的关系.当某条信息出现与并查集中记录的信息不符合时,则此信息不合法.…
并查集专题训练地址,注册登录了才能看到题目 并查集是一个树形的数据结构,  可以用来处理集合的问题, 也可以用来维护动态连通性,或者元素之间关系的传递(关系必须具有传递性才能有并查集来维护,因为并查集有压缩路径). 用并查集来维护元素之间关系的传递, 那么元素与元素之间就有一个权值(带权并查集),那么当路径压缩时,我们需要根据关系的传递性来维护 当父元素变动时,关系的变动. poj1182食物链 给定一些元素之间的关系, 问我们有多少是错误的. 当碰到一个错误时,并不会用它来更新并查集(错误的怎…
POJ1733 Parity game Description Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You choose a continuous subsequence (for example the subsequence from the third to the fifth…
POJ1733 Parity game Description Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You choose a continuous subsequence (for example the subsequence from the third to the fifth…
[POJ1733]Parity game 题面 vjudge 题解 比较简单的分类并查集 将一个查询操作看作前缀和\(s_r-s_{l-1}\)的奇偶性 将每个点拆成一奇一偶然后分别连边即可 如果一个点的奇点和偶点被连在一起了就判无解即可 代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include…
题目链接:https://vjudge.net/problem/POJ-1733 解题思路:并查集+离散化 AC代码: #include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <map> #include <cstring> #include <cmath> using namespace std; ; st…
题目链接: http://poj.org/problem?id=1733 题意: 输入n表示有一个长度为n的0,1字符串, m表示接下来有m行输入, 接下来的m行输入中x, y, even表示第x到第y个字符中间1的个数为偶数个, x, y, odd表示第x到第y个字符中间1的个数为奇数个, 若m句话中第k+1是第一次与前面的话矛盾, 输出k; 思路: 若x, y之间1的个数为偶数个, 那么1~x 与1~y中1的个数同奇偶性, 反之则异奇偶性, 我们可以将其理解为若输入x, y, even, 即…
题意:有一个 0/1 数列,现在有n组询问和回答,表示某个区间内有奇数或者偶数个1,问到前多少个都没有逻辑错误,而下一个就不满足 可以定奇数为 1 偶数为 0作为每个元素的权值,表示它与它的祖先元素的差距,这样通过 mod2 可以直接表示两奇或两偶都得偶,奇偶得奇,然后就是对前序1的个数和做并查集的操作,注意对于一个区间[a,b],合并的两个元素是 a-1 和 b .直到找到错误就可以了.由于区间太大,可以离散化各个需要合并的元素,再离线操作并查集. #include<stdio.h> #in…
Description Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You choose a continuous subsequence (for example the subsequence from the third to the fifth digit inclusively) a…
题目大意:有一个长度为n的0,1字符串, 给m条信息,每条信息表示第x到第y个字符中间1的个数为偶数个或奇数个, 若这些信息中第k+1是第一次与前面的话矛盾, 输出k; 思路:x, y之间1的个数为偶数个, 那么1~x 与1~y中1的个数奇偶性相同:若x,y间1的个数为奇数个,那么1~x与1~y中1的奇偶性相同.奇偶性相同的加入同一个并查集 eg:数据范围大,先离散化 #include<stdio.h> #include<algorithm> #define N 100006 us…