题意: 寻找异或后值为 u,相加后和为 v 的最短数组. 思路: 异或得 u ,则 v 至少应大于等于 u ,且多出来的部分可以等分为两份相消. 即初始数组为 u , (v-u)/2 , (v-u)/2,之后即为特判或判断是否可以合并. #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll u,v;cin>>u>>v; ll a=(v-u)/2; if(v&…
题意: 给有 n 个点的树的 n-1 条边从 0 到 n-2 编号,使得任意两点路径中未出现的最小数最小的方案. 思路: 先给所有度为 1 的点所在边编号,之后其他点可以随意编排. #include <bits/stdc++.h> using namespace std; const int M=110000; vector<vector<int>> e(M); vector<pair<int,int>> a; map<pair<in…
题意: GCD(a,b) + LCM(a,b) = n,已知 n ,求 a,b. 思路: 设 gcd(a, b) = k, a = xk, b = yk , k + ab / k = n xy = n/k - 1 令 k = 1 , 则 xy = n - 1 令 x = 1 , 则 y = n - 1 ∴ a = xk = 1 , b = yk = n-1 一定满足条件. #include <bits/stdc++.h> using namespace std; typedef long lo…
传送门 题意: 给出一个数x,有两个操作: ①:x ^= 2k-1; ②:x++; 每次操作都是从①开始,紧接着是② ①②操作循环进行,问经过多少步操作后,x可以变为2p-1的格式? 最多操作40次,输出操作数和所有操作中步骤①的操作数的k: 我的思路: 操作①每次都是异或 (k-1) 个1: 我们最终的结果是将 x 变为(p-1)个1: 那么,我们只要每次异或操作都将x中最高的0位变为1: 因为x最多只有20位,所以,完全可以在40个操作内将x变为(p-1)个1: 例如: 7654321(位置…
Problem   Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem Description Input The first line contains one string s (1≤|s|≤5000) — the initial name, which consists only of lowercase Latin letters. It is guarante…
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the follow…
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have three piles of candies: red, green and blue candies: the first pile…
F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树,满足只有一个点的权值最小,然后除开这个点,每个点都有一个权值比它更小的点与之相邻. 然后要求你重构这颗树,满足点权及边权和最小. 点权计算方法: au = au*num(num为与之相邻边的个数); 边权计算方法: e{u,v},we = dis(u,v)*min(au,av)  (dis(u,v…
E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个数,找出k个连通块,使得连通块里面点的和除以k最大.当选择不同数量的连通块有相同的最大值时,要求输出k最大的情况. 题解: 由于这个不等式average(x1,x2,x3...xn)<=max(x1,x2,...xn)成立(当且仅当x1=x2=...xn时,等号成立),而题目所求正好是连通块里面点和…
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Description: This is an interactive problem! Ehab plays a game with Laggy. Ehab has 2 hidden integers (a,b)(a,b). Laggy can ask a pair of integers (c,d)(c,d) a…
B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减去最小值,输出这个最小值,k用不完用0来补. 题解: 考虑到重复的数会被一起减去,所以我用了个set来存放这n个数,然后用个累加器记录下减去了多少最小值,把数取出来时减去这个累加器就好了,最后用0来补. 代码如下: #include <bits/stdc++.h> using namespace…
A. Ehab and another construction problem 题目链接:https://codeforc.es/contest/1088/problem/A 题意: 给出一个x,找出这样的a,b满足:1<=a,b<=x,并且a%b=0,a/b<x,a*b>x. 题解: 赛后发现,除开x=1的情况,其它情况a=b=x就可以满足条件了... 但还是附上比赛时候的代码吧... #include <bits/stdc++.h> using namespace…
链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer ii from 22 to nn, assign a positive integer aiai such that the following conditions hold: For any pair of integers (i,j)(i,j), if ii and jj are coprime…
链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can perform the following operation on it as many times as you want: Pick two integers ii and jj (1≤i,j≤n)(1≤i,j≤n) such that ai+ajai+aj is odd, then swap…
链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it possible to reorder it in such way so that the sum of the first nn elements isn't equal to the sum of the last nn elements? 思路: 排序后求前一半和后一半的和比较. 代码: #…
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <algorithm> #inclu…
后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https://codeforces.com/blog/entry/67388 有助于理解树链剖分 和 点分治 题解写得挺好 重链 重链中的点的子树的大小是最大的 重链外的点作为根节点的 子树 大小 < 1/2总的点数目 每次处理后到达重链外的点(若是重链内的点,判断结束) #include <cstdio&g…
C. Ehab and a 2-operation task 数学 mod运算的性质 题意: 有两种对前缀的运算 1.对前缀每一个\(a +x\) 2.对前缀每一个\(a\mod(x)\) 其中x任选 思路:这里只有加法 所以膜运算可以看作是减法 而膜运算当成减法使用需要合理运用其性质 \(a[i]=k*n+b\) \(a[i]\equiv{b}\pmod{m}\) 只要使得\(a[i]==i\)即可满足题意 而由上式我们知道\(a[i]\equiv{b}\pmod{m}\) 只要看\(b\)和…
1325A - EhAb AnD gCd 题意:随意找两个数是他们的最大公约数 GCD 与最小公倍数 LCM 之和为所给定的值. 思路:找一下规律 ,假设所给的 数位n, 那么我们将n分成 1 ,n-1,这两个数,总是附和我们的答案 收获:认真观察所给的条件,自己先构造一下,找找规律 1325B - CopyCopyCopyCopyCopy 题意 :给一个有n个元素的数组,将数组中的元素复制 n 次,将n复制结果拼接起来,形成以新的数组,让求严格递增子序列有多少个 思路:对给的数组排序去重复,剩…
人闲桂花落,夜静春山空. 月出惊山鸟,时鸣春涧中.--王维 A. EhAb AnD gCd You are given a positive integer x. Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x. As a reminder, GCD(a,b) is the greatest integer that divides both a and b. Similarly, LCM(a,b)…
题目链接:https://codeforces.com/contest/1364/problem/C 题意 给出大小为 $n$ 的非递减数组 $a$,构造同样大小的数组 $b$,使得对于每个 $i$,$b_1, b_2, \ldots, b_i$ 中未出现的最小正整数均为 $a_i$ .($1 \le n \le 10^5, 0 \le a_i \le i, 0 \le b_i \le 10^6$) 题解 一个比较重要的结论: \begin{equation} if\ a_i \neq a_{i…
参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/Dup4/p/10068891.html…
传送门 https://www.cnblogs.com/violet-acmer/p/10068786.html 题意: 给定一个长度为 n 的数组a[ ],并且有两种操作: ①将前 i 个数全都加上 x; ②将前 i 个数全都 mod x 要求用不超过 n+1 次操作,使得数组 a[ ] 严格单调递增. 题解: 预备知识补充: 假设 a > b,在什么条件下可以使式子 a%(a-b) == b 成立 ? 只有当 a > 2*b 时才成立. 证明如下: 用反证法,假设 a < 2*b,那…
题意:给出树 求最大的sigma(a)/k k是选取的联通快个数   联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值  这里先要满足最大平均值  而首先要满足最大  也就是一个数的时候可以找出最大值 满足第二个条件最长 也就是看最大值有多少个连续即可 而本题 也就是先找出最大值然后看直接先求出最大的一个联通快的max(sigma(a)) 然后算一共有多少个联通快等于这个最大的sigma即可 一开始还当dp做其实是个傻逼题.. #include<bits/stdc++.h> #de…
题目 题意: 0≤a,b<2^30, 最多猜62次. 交互题,题目设定好a,b的值,要你去猜.要你通过输入 c d : 如果 a^c < b^d ,会反馈 -1 : 如果 a^c = b^d ,会反馈  0 : 如果 a^c > b^d ,会反馈  1 : 每次猜前面都用 ? 表示, 最后一行用!表示已经知道a b的值. 思路: 不会,然后去找别人博客学.  大致思路就是:a b都是二进制来表示,从高到低位 把a和b的每一位都判断出来. 判断a b同一位是否相等: 1. 如果相等,判断这…
题意: 给你一个数组,可以像题目那样无限拼接,问递增子序列的最大长度(可不连续). 思路: 序列的最大长度即为数组中不同元素的个数. Tips: 一开始不知道back-to-back什么意思,看到题目立刻懂了2333. #include <bits/stdc++.h> using namespace std; void solve(){ int n;cin>>n; set<int> s; for(int i=0;i<n;i++){ int t;cin>>…
题意:有长度为\(n\)的数组\(a\),要求构造一个相同长度的数组\(b\),使得\({b_{1},b_{2},....b_{i}}\)集合中没有出现过的最小的数是\(a_{i}\). 题解:完全可以按照题意直接构造,但是比较麻烦,这里我们先标记原数组中的数,然后将原数组中没出现过的数存进\(b\)中(\(a\)中出现的数在\(b\)中不能出现在\(a\)位置之前),然后我们遍历原数组,如果\(a[i]\ne a[i-1]\),直接输出前一个数,否则输出\(b\)的队头. 构造题还是要自己多想…
题目链接:http://codeforces.com/contest/703/problem/D 思路:看了神犇的代码写的... 偶数个相同的数异或结果为0,所以区间ans[l , r]=区间[l , r]每个数相异或^区间[l , r]出现过的数相异或.如数组1,2,1,3,3,2,3,则ans[1 , 7]=(1^2^1^3^3^2^3)^(1^2^3) 前半部分可以处理出前缀异或,后半部分先对询问按r进行排序,处理过程中相同的数只保留最后一个. #include<bits/stdc++.h…
题目链接:http://codeforces.com/contest/703/problem/D 给你n个数,m次查询,每次查询问你l到r之间出现偶数次的数字xor和是多少. 我们可以先预处理前缀和Xor[i],表示1~i的xor和.因为num^num=0,所以Xor[r] ^ Xor[l - 1]求的是l~r之间出现奇数次的数字xor和. 那怎么求偶数次的呢,那我们可以先求l到r之间不重复出现数字的xor(比如1 1 2 求的是1 ^ 2),然后再xor以上求出的Xor[r] ^ Xor[l…
A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/556/problem/A Description Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros an…