Codeforces 题目传送门 & 洛谷题目传送门 u1s1 感觉这个题作为 D1C 还是蛮合适的-- 首先不难发现答案不超过 \(20\),所以可以直接暴力枚举答案并 check 答案是否合法,当然二分也是没问题的,转最优性问题为判定性问题. 考虑怎样判断一个答案 \(k\) 是否合法,由于所有相连的线 \(u,v\) 都有 \(2^k\mid a_u\oplus a_v\),那么 \(a_u\bmod 2^k=a_v\bmod 2^k\) 一定成立.因此我们可以将每个点的权值看作 \(a_…
考虑\(2^x | (u \oplus v)\)的最大\(x\)小于等于\(20\) 这种题目,可以考虑搬到图上做. 我们枚举\(x\)那么对\((u\ mod\ 2^x,v\ mod\ 2^x)\)连边. 有答案当且仅当存在欧拉回路.…
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative…
有n个珠子,每颗珠子有左右两边两种颜色,颜色有1~50种,问你能不能把这些珠子按照相接的地方颜色相同串成一个环. 可以认为有50个点,用n条边它们相连,问你能不能找出包含所有边的欧拉回路 首先判断是否在一个联通分量中,在判断是否存在欧拉回路,最后输出欧拉回路. #include <stdio.h> #include <string.h> ; <<; int mx,mn,p[maxn],d[maxn],G[maxn][maxn]; int find(int x) { re…
Codeforces 526 D 题意:给一个字符串,求每个前缀是否能表示成\(A+B+A+B+\dots+A\)(\(k\)个\(A+B\))的形式. 思路1:求出所有前缀的哈希值,以便求每个子串的哈希值.然后枚举\(A+B\)的长度,二分\(A\)的长度,用哈希检查一下字符串是否相等即可. 思路2:求出KMP的\(fail\)数组,然后枚举前缀的长度\(len\),看该前缀的最小循环节\(min=len-fail_{len}\)(因为\(A+B+A+B+\dots+A+B+A\)中前缀\(A…
2019-02-09-21:55:23 原题链接 题目描述: 给定一串珠子的颜色对,每颗珠子的两端分别有颜色(用1 - 50 之间的数字表示,对每颗珠子的颜色无特殊要求),若两颗珠子的连接处为同种颜色则可以相连, 当整串珠子都满足两两可以相连时则输出连接序列,否则输出some beads may be lost. 解题思路: 简单欧拉回路思维,注意判断该图是否可以构成欧拉回路. 算法描述及其实现: #include <bits/stdc++.h> using namespace std; +…
As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish. He has marked n distinct points in the plane. i-th point is point (xi, yi). He wan…
D. Om Nom and Necklace time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Om Nom found a thread with n beads of different colors. He decided to cut the first several beads from this th…
题目链接:点击打开链接 题意: 给出n个点m条无向边的图 開始图里没有边.每次加一条边,然后输出图里欧拉回路的条数. 思路: We will count the number of ski bases including the base consisted of empty subset of edges (before printing just subtract one). In the beginning the number of bases is equal to 1. If we…
题目简述:给定简单(无自环.无重边)连通无向图$G = (V, E), 1 \leq n = |V| \leq 2.5 \times 10^5, 1 \leq m = |E| \leq 5 \times 10^5$,保证任意节点的度数$\geq 3$.给定参数$1 \leq k \leq n$,要求完成以下任务之一: 1. 找到一条包含至少$\frac n k$个节点的简单路径. 2. 找到$k$个简单环,使得 2.1. 每个环包含少于$\frac n k$个节点,且包含的节点个数不得被$3$整…