Codeforces 15E Triangles - 组合数学】的更多相关文章

Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but…
Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by t…
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are nn bricks lined in a row on the ground. Chouti has got mm paint buckets of different colors at hand, so he painted each brick in on…
题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah$是不可用的.(压根感觉不可优化) 考虑向量的做法:$S = \frac{1}{2}(A \times B + B \times C + C\times A)$.(相当于把一个三角形拆成了三个以原点作为其中一个顶点的"有向"三角形) 于是考虑利用向量叉积对向量加法的分配律进行优化. 枚举第…
Acingel is a small town. There was only one doctor here — Miss Ada. She was very friendly and nobody has ever said something bad about her, so who could've expected that Ada will be found dead in her house? Mr Gawry, world-famous detective, is appoin…
H - Benches Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south pa…
Brief Introduction: 求从N出发,回到N且不包含任何黑色三角的路径数 Algorithm:假设从N点到第二层中间的节点M的路径数为k,易知总路径数为(k*k+1)*2 而从第第四层开始,每两行之间的形状是具有规律的,我们称之为一个“凹槽”. 每个“凹槽”的方案数是具有规律的:2n-2到2n间的方案数F(n)=2^n-3(不考虑从最外层跳到次外层) 所以到恰好到第2n层的总方案数S(n)=4*F(3)*F(4)......*F(n),res=6+S(3)+S(4)....+S(n…
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i. Your task is t…
题面: 传送门 分析: 此题O(n2l)" role="presentation" style="position: relative;">O(n2l)O(n2l)模拟肯定是会超时的(l为所有字符串总长) 我们想到对字符串进行一定的预处理,可以快速计算匹配 我们设每一个(的值为1,)的值为-1,规定 若只有)括号多了x个,则l[i]=r[i]=-x<0 若只有(括号多了x个,则l[i]=r[i]=x>0 那么如何求l[i],r[i]的值呢…
题面 传送门 题目大意:给出一个无向图,每个节点可以填1,2,3三个数中的一个 问有多少种填数方案,使两个相邻节点的数之和为奇数 分析 如果图中有奇环,一定无解 我们对图黑白染色,由于图可能不联通,记第i个连通分量的黑点数量为\(b_i\),白点数量为\(w_i\) 观察发现每一条边的连接的两个节点,一个是2,另一个是1或3 显然要不黑点全部填2,要不白点全部填2 若黑点填2,则剩下的白点有\(2^{w_i}\) 种填法 若白点填2,则剩下的黑点有\(2^{b_i}\) 种填法 总答案为: \[…
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph are playing a two-player game on a triangular board that looks like the following: 1 2 3 4 5 7 8 6 9 10 11 13 14 16 17 12 15 18 At each turn, a playe…
C. Love Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/553/problem/C Description There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie.…
D. Vanya and Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/problem/D Description Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as…
E. Alyona and Triangles 题目连接: http://codeforces.com/contest/682/problem/E Description You are given n points with integer coordinates on the plane. Points are given in a way such that there is no triangle, formed by any three of these n points, which…
codeforces 932E Team Work 题意 给定 \(n(1e9)\).\(k(5000)\).求 \(\Sigma_{x=1}^{n}C_n^xx^k\). 题解 解法一 官方题解 的做法,网上有很多,就不写了. 解法二 从组合数学的角度入手. 参考博客 我们可以这样理解这个式子 \(\Sigma_{x=1}^{n}C_n^xx^k\) :有 \(n\) 种小球,从中选出 \(x\) 种,再选出 \(k\) 个小球,这 \(k\) 个小球只能来自选定的 \(x\) 种类别.求方案…
https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1$ 就是左边一个色右边一个色, $m(m-1)$ ,再选转折点有 $i-1$ 种 $C_{i-1}^{1} $( $i$ 个球. $i-1$ 个空挡都可以插). 到 $k=2$ 呢?可以是三种不同颜色,也可以是左右左,也就是 $m(m-1)(m-1)$ ,再选转折点有 $C_{i-1}^{2}$ .…
time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard output Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many tri…
Codeforces Round #142 (Div. 1) C. Triangles 题目链接 今天校内选拔赛出了这个题,没做出来....自己思维能力还不够强吧.我题也给读错了.. 每次拆掉一条边,可以考虑在原图中会破坏多少三角形,但这也不好统计:所以可以转化一下,在新图中是什么样子的. 原图中会破坏三角形的话,那么在新图中,那些没有被\(a,b\)两个点连接的点的个数就应当是破坏的个数.这个好统计,就是\(n-du[a]-du[b]+\)与\(a,b\)同时相连的点的数量.这个容斥一下就出来…
Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学 [Problem Description] ​ 给你\(n\)个\(1\),\(m\)个\(-1\),他们任意排列有\(\frac{(n+m)!}{n!\cdot m!}\)中排列,每种排列都有一个最大前缀和(可能为\(0\)),求所有排列的最大前缀和之和为多少. [Solution] ​ 定义\(dp[i][j]\)表示有\(i\)个\(…
题面 传送门:http://codeforces.com/problemset/problem/840/C C. On the Bench time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A year ago on the bench in public park Leha found an array of n numbers. L…
Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal to powers of two. He has \(a_0\) sticks of length \(2^0=1\), \(a1\) sticks of length \(2^1=2\), ..., \(a_{n−1}\) sticks of length \(2^{n−1}\). Pavel wa…
Codeforces 11194F (组合数学) 传送门:https://codeforces.com/contest/1194/problem/F 题意: 你有n个事件,你需要按照1~n的顺序完成这些事件,每个事件需要\(t_i\)的时间完成,你现在一共有T的时间去做这些事情,每做一件事情的时候,你有0.5的概率花费\(t_i\)的时间完成他,也有0.5的概率花费\(t_i+1\)的时间去完成他,如果在做这个事件的时候时间花完了,你就相当于没有做成这个事件,现在问你在T的时间内完成的事件的个数…
链接:https://codeforces.com/problemset/problem/1284/C 题意:定义一个framed segment,在区间[l,r]中,max值-min值 = r - l.求有1-n 组成的序列中,所有framed segment的个数%m 思路:组合数学推一个结论.例如假设1到n组成的序列中,求长度为k的framed segment,那么其一段序列的最大值 - 最小值 = k,例如n = 5,k = 3,这些framed segment 必定是 1 2 3 或者…
Codeforces 题面传送门 & 洛谷题面传送门 首先对于这样的题目,我们应先考虑如何计算一个括号序列 \(s\) 的权值.一件非常显然的事情是,在深度最深的.是原括号序列的子序列的括号序列中,必定存在一个满足前面只由一段左括号,后面只由一段右括号组成,因此我们考虑枚举这中间位置在原括号序列中对应哪个位置,那么假设这个断点位于 \(i\) 和 \(i+1\) 之间,我们设 \(i\) 及之前有 \(x\) 个左括号,\(i+1\) 及之后有 \(y\)​​ 个右括号,那么显然以这个位置为端点…
http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代码: //File Name: cf659G.cpp //Author: long //Mail: 736726758@qq.com //Created Time: 2016年07月12日 星期二 12时40分28秒 #include <stdio.h> #include <string.h…
题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a…
Alyona and Triangles 题目连接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/J Description You are given n points with integer coordinates on the plane. Points are given in a way such that there is no triangle, formed by any three of these n point…
http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目大意:给n条直线,保证直线两两不平行,保证三条直线不公点.然后,随机挑三条直线,构成一个三角形,问挑出的三角形的面积的期望. 换句话说,就是算出全部三角形的面积和.再除以三角形的数量.后者是C(n,3), 关键是三角形面积和怎样计算. 下面给我我的思路:O(n^2) 基于三角形的向量表示法, S(A…
原文链接http://www.cnblogs.com/zhouzhendong/p/8848990.html 题目传送门 - CodeForces 623E 题意 给定$n,k$. 让你构造序列$a(0<a_i<2^k)$,满足$b_i(b_i=a_1\ or\ a_2\ or\ \cdots\ or\ a_i)$严格单调递增.($or$为按位或) 问你方案总数.对$10^9+7$取模. $n\leq 10^{18},k\leq 30000$ 题解 毛爷爷论文题. 我怀疑我看到的是假论文.里面…
题面: http://codeforces.com/problemset/problem/407/C 一句话题意:给一个长度为n的序列g,m次操作,每次操作(l,r,k)表示将g[l]~g[r]的每个数g[j](l<=j<=r)加上c(j-l+k,k),输出经过m操作后的最终序列(mod 1e9+7)(n,m<=1e5,k<=100). 题解: 首先看到这个题瞬间想到数据结构,但发现一次修改操作中每个点的增加值都不同后果断放弃.又因为发现这题只有一次询问,就考虑能不能先将每次操作存…