CodeForces - 766B Mahmoud and a Triangle】的更多相关文章

[题意概述] 给定一串数,从中挑三个,判断能否组成一个有正面积的三角形,如果能就输出YES,否则就输出NO [题目分析] 将 n 个数从大到小进行排列,三个三个往下去判断,只要后两个的和比第一个大的时候就满足条件. [AC] #include<bits/stdc++.h> using namespace std; bool cmp(int a,int b) { return a > b; } int main() { int n; ]; int ans = false; while(~s…
B. Mahmoud and a Triangle 题目连接: http://codeforces.com/contest/766/problem/B Description Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't…
地址:http://codeforces.com/contest/766/problem/A A题: A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output While Mahmoud and Ehab were practicing for IO…
B. Mahmoud and a Triangle time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to…
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列且最小. 思路 其实这题乱搞就行了.用到了之前HDdalao教我的素因子分解方法,可以快速地对枚举的数进行检测. 我们维护一个当前已填的数的素因子集合以及一个大于1的自然数集合(考虑最坏情况,我们总可以都用素数来构造这个序列.由素数的密度可知,n/ln(n)要大于1e5,所以该自然数集合上限达到2e…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangl…
D. Mahmoud and a Dictionary time limit per test:4 seconds memory limit per test:256 megabytes input:standard input output: standard output Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types o…
D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of…
传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Ol…
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair…
题目:http://codeforces.com/contest/1058/problem/D 题意:有一个大小为N*M的矩阵内,构造一个三角形,使面积为(n*m)/k.若存在输出三个顶点(整数). 分析: 首先可以判断,若(2*n*m)%k!=0,一定为NO. 其次,可以想到,三角形可以构造为一个顶点为(0,0)的直角三角形.且满足等式  (2*n*m)%k==0 如果k是偶数,那个k肯定可以和2约分,所以把k除2. 再得到tmp=gcd(n,k),x=n/tmp,就是说能用n约掉一部分k就约…
题目链接:http://codeforces.com/problemset/problem/766/E 大意,给出一个$n$个点的树,每个点都有一个权值,令$Disx$为$u$到$v$路径上的异或和求: $${\sum _{i=1}^{n-1}\sum _{j=i}^{n}Disx(i,j)}$$  枚举我当前处理的是这个二进制位上第$k$位的值,就只需要统计每个点的子树中有多少个点到当前点的第$k$位的异或和为$0$,为$1$的分别有多少个,统计答案即可.   #include<iostrea…
C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strin…
862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) ; bool color[N]; vector<int>g[N]; ; int…
862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了,0异或x等于x.所以只要把剩下的异或起来变成x就可以了.如果剩下来有3个,那么,这3个数可以是x^i^j,i,j. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back…
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这个字符串与目标串之间不同的字符的个数.要在15次的提问内,找到目标串中任意一个1和0的位置. 题解: 因为是15次提问,其实可以想到二分,但是分别对0和1进行二分差不多要二十多次,所以可以对01或10进行二分,查找某一个01或10串的位置. #include<bits/stdc++.h> usin…
C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strin…
题目链接 Mahmoud and a xor trip 树形DP.先考虑每个点到他本身的距离和,再算所有点两两距离和. 做的时候考虑二进制拆位即可. #include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i(0); i < (n); ++i) #define rep(i, a, b) for(int i(a); i <= (b); ++i) #define LL long long const…
传送门:http://codeforces.com/contest/1058/problem/D 题意: 在一个n*m的格点中,问能否找到三个点,使得这三个点围成的三角形面积是矩形的1/k. 思路: 这个题就是找(0,0)(a,0)(0,b)中的a和b,可以得到2*n*m/k = a*b.所以2*n*m%k != 0答案就不存在.接下来就是把等式左边的分母消去,得到a,b的分配值. 如果k是偶数,那个k肯定可以和2约分,所以把k除2. 再得到g = gcd(n,k),a = n/g,就是说能用n…
题目链接:http://codeforces.com/contest/862/problem/E 题解:水题显然利用前缀和考虑一下然后就是二分b的和与-ans_a最近的数(ans_a表示a的前缀和(奇加偶减)) #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; typ…
题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找两遍第一遍找1第二遍找0但是这样肯定超时所以还不如直接找相邻的01串或者10串具体查找方法是先将所有串赋值为0这样就能得到1的总个数,然后将所要求的区间全赋值为1其他赋值为0.设num1为总的1的个数反馈的值其实就是表示L-R之间0的个数,然后只要满足(设返回的数为now)只要满足num1-now<…
D. Vasya and Triangle time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vasya has got three integers n, m and k. He'd like to find three integer points (x1,y1), (x2,y2), (x3,y3), such that 0≤x1,x…
题目大意:n个字符串,支持修改一个位置上的字符串和查询一个区间的子区间中长度乘LCP的最大值,输入字符数和询问数不超过10^5. 做法:求出相邻的LCP长度,区间LCP等于区间最小值,查询分几种情况考虑,一种只有一个串,线段树维护长度最大值即可:若有若干个串,设一个阈值k,若答案的LCP<=k,对于小等k的每一个i,若一个位置的相邻LCP大等i,设为1,否则设为0,即求区间最长连续1,每种i开一棵线段树维护即可:若LCP>k,我们把相邻LCP长度超过k的位置存进set,查询的时候拿出来,直接建…
<题目链接> 题目大意: 给定一个数n,代表有一个0~n-1的完全图,该图中所有边的边权为两端点的异或值,求这个图的MST的值. 解题分析: 数据较大,$10^{12}$个点的完全图,然后异或又暂时推不出什么性质,所以先起手Kruskal打一张小数据完全图的MST的表,发现规律其实还是蛮好找的. #include <bits/stdc++.h> using namespace std; ; int fa[N],cnt,ncase; struct Edge{ int u,v,w; b…
<题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的   Hamming distance ,现在要求你按照步骤进行交互式操作,最终得到任意一个0.1的下标. 解题分析:因为原串中至少存在一个0和一个1,所以一定存在一个01或者10序列,因此我们可以用二分来寻找这个序列(注意二分过程中选择区间的操作).二分之后,一定能够得到01或10序列,然后将其按先0后1的顺序输出即可. #i…
<题目链接> 题目大意: 给出n.m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO",本题中所有数均需小于1e6. 解题分析:因为本题是SPJ,且当n比较大的时候,需要输出很多数,所以我们试着去构造这n个数,力图找出一些规律.n<=2的时候很好直接进行特判即可.n>=3的时候,可以直接进行简单的构造,比如前面n-1项依次设为1,2,3,……(下面假设前面这些连续的项异或结果为r…
题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串的不同位的数目.求任意一个\(0\)和\(1\)的位置. \(n\leq 1000\). \(Solution\) 通过\(0...\)和\(1...\)就可以判断出第一个数是什么.然后二分,对每个区间判断是否全为\(0/1\),就可以找到另一个了. 为啥有时候用read()会T.. #includ…
题目链接 \(Description\) 有一张\(n\)个点的完全图,从\(0\)到\(n-1\)标号,每两点\(i,j\)间的边权为\(i\oplus j\).求其最小生成树边权之和. \(Solution\) 为方便,以下点从\(0\)到\(n\)编号. 每个点\(x\)应和\(x\oplus lowbit(x)\)相连,边权为\(lowbit(x)\)(\(lowbit(x)\)会和\(0\)相连,所以一定能构成树),所以答案为\(\sum_{i=1}^nlb(i)\). 继续优化.注意…
并查集. 将每一个物品拆成两个,两个意义相反,然后并查集即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set>…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 参考这篇题解:https://blog.csdn.net/mitsuha_/article/details/82825862 为什么可以保证mgcd(2n,k)/k是一个整数? 因为先前已经判断过 2nm/k是可以整除的. 显然k是被2n和m两个数字除了之后变成1 2n贡献的那一部分其实就是gcd(2n,k) 那么我们显然可以直接用gcd(2n,k)来代表2*n 所以右边肯定也是能整除的. 且<=m [代码] #include <bit…