题意:构造让Dijkstra单源最短路算法有效松弛次数最多的数据... 题解:构造,题意换种说法就是更新晚的路径要比更新早的路径短.因为所有点都会更新一次,那么按照更新时间形成一条链,即到最后一个点的最短路径, 注意:越在这条链的后面的边越晚更新,然后添加边,在前面的点所连的边一定是先更新的,所以反过来添加边的时候只要保证比之前的路径更长就行了. #include<bits/stdc++.h> using namespace std; typedef long long ll; #define…
Identity Checker 题目连接: http://codeforces.com/gym/100015/attachments Description You likely have seen that x(sin x +cos2 x) ! x = 0, and you may have seen that sin(2x) ! 2 sin x cos x =0. But did you know that tan (2x)(x ! x tan2 x) ! 2x tan x = 0? Wo…
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description Andrew is having a hard time preparing his 239-th contest for Petrozavodsk. This time the solution to the problem is based on Di…
之前几乎没写过什么这种几何的计算题.在众多大佬的博客下终于记起来了当时的公式.嘚赶快补计算几何和概率论的坑了... 这题的要求,在对两圆相交的板子略做修改后,很容易实现.这里直接给出代码.重点的部分有:两圆在相离(或外交)时输出第一个圆的面积.内涵(或内切)则需要分类讨论,是羊的圈大.还是狼的圈大.以下是代码: #include<iostream> #include<cmath> #include<stdio.h> using namespace std; int ma…
01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define MAXW 15005 #define N 155 #define LL long long #define MOD 1000000007 int w1[N],w2[N]; LL dp1[MAXW],dp2[MAXW]; int main(…
emmmm.... 在被新生暴打后,我花了很久才补出这道DFS.由于WA1检查了半天,最后竟然是输出少了一个:   ,心态小崩. 这里普通的dfs算出的连通区域并不能直接当做最后的答案.所以需要类似模拟的DFS来处理. 代码如下: #include<iostream> using namespace std; int q[12][12];//用数组标记该位置是空地.食物.还是障碍. int pd[12][12];//判断有没有走过 int maxx=0;//记录最大路径长度 int a,b,m…
算数学期望,每个人都可以分开来考虑.Xi表示第i个人跑到另外一边的次数. Xi服从二项分布.概率的和是个二项式,(p+1-p)^T,把二项式展开,p的偶次项是留在原来那一边的概率. 可以用((a+b)^T+(a-b)^T)/2来算出偶次项之和. 也可以用矩阵快速幂.矩阵构造如下 #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue>…
A. Queries time limit per test:0.25 s memory limit per test:64 MB input:standard input output:standard output Mathematicians are interesting (sometimes, I would say, even crazy) people. For example, my friend, a mathematician, thinks that it is very…
题意:麦田的故事,n张牌,取x张牌,记住前x张牌最大的值m,继续往后取,遇到第一张比m大的牌就停下来.求一个x使得最后的牌在整副牌里是最大的期望最大. 假设最大的牌是A,A在各种位置出现的概率就是相等的,因为题目不要求输出概率,所以当成1.在A固定的情况下,在它前面的牌中最大的牌B,出现在各个位置的概率也是相等的,计算一下各个事件的概率. 当X固定的时候,B出现在它前面的事件概率和就是成功的概率,所以问题就转化成了求一个X,使得下面这个矩形框中的概率和最大. 样例,n=5 并不需要用组合数打表算…
傻逼题,但是为什么别人的O(n^3)不会T?只是因为用了bitset优化... 附上一张bitset基本操作的表 #include<bits/stdc++.h> using namespace std; +; char g[maxn][maxn]; bitset<maxn> b1[maxn],b2[maxn],res; #define local int main() { #ifdef local freopen("triatrip.in","r&qu…
如果直接模拟水向周围流会TLE,因为某些个结点被重复扩展了多次, 科学做法是topo排序,每次只把入度为0的点放入队列,这样就严格保证了每个结点只被扩展一次. #include<bits/stdc++.h> using namespace std; #define eps 1e-9 #define bug(x) cout<<#x<<'='<<x<<endl; #define Min 1e-7 ; ; struct Ponds { double c…
题意:给出一堆元素,求一个子集,使子集的乘积最大,如有多个,应该使子集元素个数尽量小. 题解:贪心,如果有大于1的正数,那么是一定要选的,注意负数也可能凑出大于1的正数,那么将绝对值大于1的负数两两配对, 如果还剩下一个绝对值大于1的负数,那么在判断一下,那个负数和比它大的最小负数的乘积是否大于1,如果是那么就选这两个. 把所有可能凑成大于1的数选完以后,剩下的数一定比1小,那么就不选. 如果无法凑出大于1的数,那么再分类讨论一下. 挺容易写错... #include<bits/stdc++.h…
题意:询问单源最短路径,每条边有一个颜色,要求路径上相邻边的颜色不能相同,无重边且边权为正. 题解:因为路径的合法性和边的颜色有关, 所以在做spfa的时候,把边丢到队列中去,松弛的时候注意判断一下颜色,d数组表示到这条边的出点v的距离. 期望复杂度是O(km),k是边入队次数,m是边数.最后根据边来松弛顶点,O(m),总复杂度是O(km+m). 一开始想的Dijkstra(看到边权为正..),存点和之前边的颜色每次更新的时候判断来的那个点的颜色和当前边的颜色是否一样,WA了,很快我就意识到,入…
关于sg函数这篇blog讲得很详细http://blog.csdn.net/logic_nut/article/details/4711489. sg函数的价值在于把复杂的游戏拆分成简单的游戏,然后通过计算出这些简单游戏的sg值得到复杂游戏的sg值. 求sg值的基本方法:是根据状态转移,有些问题可以找到规律,不能找到规律的可以通过模拟转移过程来求解. 在此蟹蟹ABacker教我sg函数的求法 #include<cstdio> #include<algorithm> using na…
题解:状态压缩之后,暴力dfs,如果有一个选择,能让对手必败,那么就是必胜态,能转移到的状态都是对手的必胜态,或者无法转移,就是必败态. 总算是过了,TLE是因为状态没判重. #include<cstdio> #include<cmath> #include<vector> #include<map> #include<set> #include<algorithm> #include<iostream> #include…
题意:给一个nXm的矩阵,上面有一些数字,从左上角出发,每次只能往右或者往下,把沿途的数字加起来,求到达右下角的最大值是多少. 题解:简单的一个dp,设f[i][j]为到达i行j列的最大值,f[i][j] = max(f[i-1][j],f[i][j-1])+a[i][j],然后用队列刷表法. #include<cstdio> #include<cstring> #include<queue> using namespace std; typedef long long…
题意:统计一些串中,字母的出现频率,不分大小写,找出现频率最高5个字符(相同频率优先取字典序大的),把他们的对应的值加起来判断以下是否大于62. 没出现的不算. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; ]; ]; bool cmp(int a,int b) { return cnt[a]>cnt[b] || (…
根据题意略推一下,其实就是问你满足(a*(a+1))/2 < m <= ((a+1)*a(a+2))/2的a和m-(a*(a+1))/2 -1是多少. 二分求解就行了 #include<cstdio> using namespace std; typedef long long ll; int main() { int T; scanf("%d",&T); ; k <= T; k++){ ll n,m; scanf("%I64d%I64d…
读懂题意就是水题,按照出现次数对下标排一下序,暴力.. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; ; ll cnt[maxn]; ll r[maxn]; bool cmp(int a,int b) { return cnt[a] > cnt[b]; } int main() { int T; scanf(&quo…
把'I'拆成容量为1一条边,一个入点一个出点,入点和相邻的'W'连一条容量为1的边,出点和相邻的'N'连一条容量为1,所有的'W'和源点连一条容量为1边,所有的'N'和汇点连一条容量为1的边,表示只能用一次.一发网络流就过了. 写了4000B+的贪心,然并卵 #include<bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; ; #define PB push_back struct Edge { int from,…
 Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Practice Description standard input/output Andréh and his friend Andréas are board-game aficionados. They know many of their friend…
 Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Practice Description standard input/output Thai cuisine is known for combining seasonings so that every dish has flavors that are…
Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Practice  Description standard input/output Ayutthaya was one of the first kingdoms in Thailand, spanning since its foundation in 1350 to…
 Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Practice Description standard input/output At the ruins of Wat Phra Si Sanphet (วดพระศรสรรเพชญ), one can find famous inscr…
思考题的说明 一.本学期高代I的思考题面向16级的同学,将不定期地进行更新; 二.欢迎16级的同学通过微信或书面方式提供解答图片或纸质文件给我,优秀的解答可以分享给大家: 三.请大家先独立解答思考题,实在做不出来的情况下,可以点击思考题的解答进行参考. *********************************************************** 1.试求下列 $n+1$ 阶行列式的值: $$|A|=\begin{vmatrix} x-n & n & & &…
1.设 $f(x)=x^n+a_{n-1}x^{n-1}+\cdots+a_1x+a_0$ 是整系数首一多项式, 满足: $|a_0|$ 是素数且 $$|a_0|>1+\sum_{i=1}^{n-1}|a_i|,$$ 证明: $f(x)$ 是有理数域上的不可约多项式. 注  上述不可约多项式的判别法称为 Osada 定理. 2.(1) 设 $\varphi$ 是 $n$ 维线性空间 $V$ 上的线性变换, $V$ 有一个直和分解: $$V=V_1\oplus V_2\oplus\cdots\op…
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an array A of integers of size N, and Q queries. For each query, you will be given a set of distinct integers S and two integers L and R that represent a…
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury of Berland regional olympiad in informatics does not trust to contest management systems, so the Berland regional programming contest is judged by th…
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT manager Linus Gates announced his next proprietary open-source system "Winux 10.04 LTS" In this system command "dir -C" prints list of all…
题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cell containing an integer, find the number of subrectangles in this grid that contain only one distinct integer; this means every cell in a subrectangle…