题解 P5937 【[CEOI1999]Parity Game】】的更多相关文章

P5937 [CEOI1999]Parity Game 洛谷P5937 P5937 [CEOI1999]Parity Game 前言: 个人感觉这道题初看想不到并查集啊!(说实话我题都没读懂,第二遍才读懂) 好了,转入正题,这道题我们可以用两种方法A掉:种类并查集&带权并查集 题目简述: 给定01序列的长度n,询问和答案的个数m 对于每行的询问和回答先给出两个整数,表示询问区间(闭区间) 再给出一个字符串回答:"odd"表示区间有奇数个1,"even"表示区…
这道题有两种做法,一种是 扩展域(种类并查集),一种是 边带权(带权并查集).种类并查集貌似应该都比带权并查集简单,所以先讲种类并查集的做法,再讲带权并查集 种类并查集 若 sum[ l ~ r ] 表示 l到r 之间1的个数,sum是一个前缀和数组,那么有 sum [ l ~ r ] = sum[ r ] - sum[ l - 1 ] .如果有sum[ l ~ r]为奇数个,那么 sum[ r ]和sum[ l - 1 ]肯定奇偶性不同:如果有sum[ l ~ r]为偶数个,那么 sum[ r…
题目链接:http://codeforces.com/contest/1272/problem/E 题目大意: 有一个长度为n的数组 \(a\) ,数组坐标从 \(1\) 到 \(n\) . 假设你现在处于数组中的某一个位置,我们假设这个坐标为 \(i\) ,那么: 如果 \(1 <= i-a[i]\) ,那么你可以从坐标 \(i\) 移动到坐标 \(i-a[i]\) 位置(花费一步): 如果 \(i+a[i]<=n\) ,那么你可以从坐标 \(i\) 移动到坐标 \(i+a[i]\) 位置(…
Content 求下面式子的奇偶性,其中 \(a_i,k,b\) 会在输入中给定. \[\sum\limits_{i=1}^k a_i\cdot b^{k-i} \] 数据范围:\(2\leqslant b\leqslant 100,1\leqslant k\leqslant 10^5,0\leqslant a_i<b\). Solution 分类讨论的题目. 我们根据 \(k\) 的奇偶性来分类讨论. 如果 \(k\) 是偶数,那么由于到了 \(i=k\) 的时候,\(a_k\cdot b^{…
C. The Game Of Parity time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play the following game:…
C. Parity Game 题目连接: http://www.codeforces.com/contest/298/problem/C Description You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes…
描述 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) and ask hi…
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…
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^(k-1)+a2*b^(k-2)+...+ak*b^0的奇偶性. 题解: 暴力求模2意义下的值就好了. 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int n; int b,k; int a[…
Parity Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12853   Accepted: 4957 题目链接:http://poj.org/problem?id=1733 Description: Now and then you play the following game with your friend. Your friend writes down a sequence consisting…
做这套题之前一直以为并查集是很简单的数据结构. 做了才发现自己理解太不深刻.只看重片面的合并集合.. 重要的时发现每个集合的点与这个根的关系,这个关系可以做太多事情了. 题解: POJ 2236 Wireless Network 10S时限,尽量做到最优吧.一开始还怕会T 预处理出能到达的点.简单题看代码就行了 #include <map> #include <set> #include <list> #include <cmath> #include &l…
题目链接:http://codeforces.com/problemset/problem/549/C C. The Game Of Parity time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n cities in Westeros. The i-th city is inhabited by ai pe…
题目链接:http://poj.org/problem?id=1733 Parity game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 3795 Description Now and then you play the following game with your friend. Your friend writes down a sequence consisting of…
ProblemSet 签到题就不写了. C. Distinct Substrings 先对原串建出SAM,map存边. 由于这题相当于添加一个字符再删除这个字符,添加下一个字符,所以每次都暴力跳后缀链接是复杂度是错的. 从 \(last\) 向上跳的时候,遍历出边,把每个拥有数字 \(c\) 的出边的第一个点编号记下来,由于后缀自动机的边数是线性的,这样复杂度就是对的 \(O(n\log n)\) 虽然 \(5e6\) 但数据水还是跑过去了. #include <iostream> #incl…
ZOJ 4081 Little Sub and Pascal's Triangle 题解 题意 求杨辉三角第n行(从1开始计数)有几个奇数. 考察的其实是杨辉--帕斯卡三角的性质,或者说Gould's sequence的知识. 其实网上很多题解都给出了答案,但大多数都只是给了一个结论或者说找规律(虽然我也是选择打表找规律先做的),但是思考为什么的时候我百度了一下,在wiki看了一些东西. wiki Pascal's triangle(https://en.wikipedia.org/wiki/P…
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我没看,看不懂. 基本思路:我不会. 参考代码:找Oyk老师和Czj老师去. B. The background of water problem 题目大意(大写加粗的水题):给定$N$个学生和他们$K$个科目的成绩$S_i$,再给出各科目$K_i$的权重顺序$Q_i$,求排名之后,拥有id为$X$的…
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #include <time.h> #include <stdlib.h> #include <string> #include <bitset> #include <vector> #include <…
2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2561 Description 给定一个边带正权的连通无向图G=(V,E),其中N=|V|,M=|E|,N个点从1到N依次编号,给定三个正整数u,v,和L (u≠v),假设现在加入一条边权为L的边(u,v),那么需要删掉最少多少条…
Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring Painting standard input/output 1 s, 256 MB    x2519 C Money Transfers standard input/output 1 s, 256 MB    x724 D Tree Construction standard input/outp…
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练. 题解: E666 这个题是让求有多少个子串只含有6.寻找连续的6,然后用n*(n+1)/2求出这一段的子串个数,然后把每一段连续的加起来. 做的时候wa了很多次,原来是在n*(n+1)的地方已经超过int型了,所以需要设置类型为long long. #include <cstdio> #inc…
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 57    Accepted Submission(s): 49 Problem Description Recently, paleoanthropologists have found historical remains on an…
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minecraft方块地图上(由很多1*1*1的方块搭起来的地图,最高5000),其中两块分别有高0.5米的激光塔,有一个高0.5米的机器人要从其中一个激光塔走到另一个.要求只能走相邻4个方向,每次不能爬上超过1格或跳下超过3格(咦,好像真的很像minecraft),要求每走到一个格子,机器人站在在这个格子的…
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或者SPFA跑出来s-t最短路,然后把最短路DAG上的每条边的容量设为1,跑最小割即可. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #define INF ((~(…
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & \equiv & a_2 \pmod{p} \\ & \vdots & \\ \sum_{i=1}^n x_i^n & \equiv & a_n \pmod{p}\end{array} \] 的解,或输出"NO". 题解 构造多项式\(\prod_i…
题意请看absi大爷的blog http://absi2011.is-programmer.com/posts/200920.html http://absi2011.is-programmer.com/posts/200822.html DAY1 T1 最优比率树形DP? 跟最优比率生成树很像..二分Σp/Σs(暂定为f 判定过程:每个点得到一个新权值f*p[i]-s[i] 做树形dp,dp[i][j]表示以i为根的子树选j个点能得到的最大权值 dp[root][k]>0则为合法 T2 T3…
又恬不知耻的开始写题解了,暑假到了,QAQ然而想我这样的弱逼是没有暑假的sad,还是老老实实刷题吧. 题目大意:给一个小车的宽度和长度和两条道路的宽度,判断小车能否通过. 思路:可以先看下面的图,我们可以得到高度h的表达式和角度 要使汽车能转过此弯道,那么就是汽车的左边尽量贴着那个直角点,而汽车的右下后方的点尽量贴着最下面的边. 我们以O点为原点建立直角坐标系,我们可以根据角a给出P点横坐标的函数F(a)   那么很容易得到:   其中有条件:,可以很容易证明是一个单峰函数,也可以不用证明,自己…
h3 { font-family: Consolas; color: #339966 } .math { font-family: Consolas; color: gray } 题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N(1<N≤500)个景点(编号为1,2,3,-,N),这些景点被M(0<M≤5000)条道路连接着,所有道路都是双向的,两个景点之间可能有多条道路.也许是为了保护该地的旅游资源,Z小镇有个奇怪的规定,就是对…
[前言] 感觉稍微有些滑稽吧,毕竟每次练的题都是提高组难度的,结果最后的主要任务是普及组抱一个一等奖回来.至于我的分数嘛..还是在你看完题解后写在[后记]里面.废话不多说,开始题解. 第一题可以说的内容不是很多吧.直接暴力,计算每种铅笔需要花费的金额. 只不过计算的时候,需要注意如下问题 如果不是整数倍,除完后要加1 神奇的Linux系统,很多人的第三个点wa了,所以要养成良好的编写代码的习惯 Code(我的源程序) #include<iostream> #include<fstream…
机器翻译 题解:模拟 #include <cstdio> #include <cstring> ; ], ]; int main(){ memset(, sizeof(in)); scanf(; ; i<m; i++){ scanf("%d", &cj); if (~in[cj]) continue; Pri ++; <=n) now ++, in[cj] = i; else { MinV = 0x3f3f3f3f; ; j<=MAXN…