题目链接:E - New Year and the Acquaintance Estimation 题解参考: Havel–Hakimi algorithm 和 Erdős–Gallai theorem 按照后面那个定理说的,枚举$k∈[1,n]$,对于每一个$k$,计算出向等式两边加入$a_{n+1}$的合法范围,最后所有范围求交即可 最后按照前面那个定理说的,枚举最终区间的时候,对于合法真正的$a_{n+1}$进行输出即可 比赛的时候没看见后面那个定理,推了半天 --------------…
洛谷 Codeforces 思路 有一个定理:Erdős–Gallai定理. 然后观察样例,可以猜到答案必定是奇偶性相同的一段区间,那么二分左右端点即可. 定理和这个猜测暂时都懒得学/证,留坑. #include<bits/stdc++.h> clock_t t=clock(); namespace my_std{ using namespace std; #define pii pair<int,int> #define fir first #define sec second…
题目地址:CF1091E New Year and the Acquaintance Estimation 首先,易知 \(ans\) 的奇偶性与所有给出的数的和的奇偶性相同 其次,易证 \(ans\) 的取值为一段连续的奇偶性相同的数,因此只需要到一个上界和下界(或者判断出无解输出 \(-1\) ) 接下来的问题就是怎么判断一个状态合不合法以及如果不合法需要加还是减 题目中给出了一个Wiki的链接:Graph realization problem 链接中给出了问题的解法:Erdős–Gall…
Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\)的格子中填入\([1,k]\)之间的数字,并且保证每一行至少有一个\(1\),每一列至少有一个\(1\),问有多少种满足条件的填充方案. [Solution] 令\(R[i]\)表示为第\(i\)行至少有一个\(1\)的方案数,\(C[i]\)表示第\(i\)列至少有一个\(1\)的方案数.则题目要…
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/B Description Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of ex…
题意:有3个杯子,排放一行,刚开始钥匙在中间的杯子,每次操作,将左右两边任意一个杯子进行交换,问n次操作后钥匙在中间杯子的概率 分析:考虑动态规划做法,dp[i]代表i次操作后的,钥匙在中间的概率,由于每次操作独立,dp[i]=(1-dp[i-1)/2; 显然,dp[1]=0; 由刚才那个式子可以得出:dp[i]-1/3=(-1/2)*(dp[i-1]-1/3),这是高中数列知识 然后 设dp[i]=p/q; dp[i]=(2^(n-1)+(-1)^n)/(3*2^(n-1)) 它要求p/q是最…
目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.New Year and the Sphere Transmission(思路) D.New Year and the Permutation Concatenation(思路 计数) E.New Year and the Acquaintance Estimation(Erdos–Gallai定理…
占个坑先,希望不要掉的太惨了吧,不要掉到上一次之前的rating upt:flag竟然没到,开心. A - New Year and the Christmas Ornament 好像没什么可说的. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector&g…
咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a,b,c; int main() { scanf("%d%d%d",&a,&b,&…
A. New Year and the Christmas Ornament 签到. #include <bits/stdc++.h> using namespace std; int a, b, c; int main() { while (scanf("%d%d%d", &a, &b, &c) != EOF) { , c - )); printf( + ); } ; } B. New Year and the Treasure Geolocati…