Problem Description It is well known that small groups are not conducive of the development of a team. Therefore, there shouldn't be any small groups in a good team. In a team with n members,if there are three or more members are not friends with eac…
/* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的图形最少要几条线 分析: 可以发现面积相同的情况下,每条线都连对角的菱形是最优的 再考虑如何将 面积为x^2的菱形,每次扩展一条边, 按最优扩展为面积为(x+1)^2的菱形 然后就可以先二分,再判断了 */ #include <bits/stdc++.h> using namespace std;…
思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组数据,使得这个程序跑出的答案是正解的三倍以上 分析: 构造一个二分图,左边 n 个节点 将左边的点进行 n 次分块,第 i 次分 n/i 块,每块的大小为 i,对于每一块都在右边建一个新的节点和这一块所有的点相连 则右边有 nlogn个节点,且每次一定优先选右边,最后取 nlogn >= 3n */…
普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ #include <bits/stdc++.h> using namespace std; #define LL long long int t, L, R, l, r, base; int dig[40], tmp[40]; LL dp[40][40][40][2]; LL DFS(int p…
题目代号:HDU 6154 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 CaoHaha's staff Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 777    Accepted Submission(s): 438 Problem Description "You shal…
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6152 Problem Description It is well known that small groups are not conducive of the development of a team. Therefore, there shouldn’t be any small groups in a good team.In a team with n members,if there…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6152 题意:判定一个无向图是否有三个点的团或者三个点的独立集. 解法:Ramsey theorem,n >= 6 直接输出 Bad 否则暴力.我是直接暴力,加个break优化就好了. #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 3e3+3; bool w[maxn][…
题目链接 Problem Description It is well known that small groups are not conducive of the development of a team. Therefore, there shouldn't be any small groups in a good team. In a team with n members,if there are three or more members are not friends wit…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/7398272.html 先考虑dp求01串的不同子序列的个数. dp[i][j]表示用前i个字符组成的以j为结尾的01串个数. 如果第i个字符为0,则dp[i][0] = dp[i-1][1] + dp[i-1][0] + 1,dp[i][1] = dp[i-1][1] 如果第i个字符为1,则dp[i][1…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6150 题意:"最小点覆盖集"是个NP完全问题 有一个近似算法是说—每次选取度数最大的点(如果有多个这样的点,则选择最后一个) 让你构造一个图,使得其近似算法求出来点数是你给定的覆盖点数的至少3倍. 解法: 可以把左边的点编号1~n,将左边的点进行n次分块,第i次分块中每块的大小为i,对于每一块的点,都在右边创建一个新节点与这些点相连. ①右边的点的度数为n,n-1,n-2,...,n/2,…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条. 解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab.最优解肯定是离 sqrt(n/2)很近的位置.想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了.我给一张做题时画的图 #include <bits/stdc++.h> using namesp…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6153 题意:给了串s和t,要求每个t的后缀在在s中的出现次数,然后每个次数乘上对应长度求和. 解法:关键在于想到把s和t都翻转之后,把t求next,然后用t去匹配s,在匹配过程中把fail指针跳到的地方加1,但是还没完,最后需要反向遍历第二个串将大串对小串的贡献加上去就可以了. 这道题是很多现场AC的代码是有漏洞的,比如bazbaba,bazbaba这个答案是34,但是很多现场AC的代码会输出31.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做一个数位DP就好了.dp[jz][start][cur][state]表示jz进制下以start位起始到cur位状态为state(1表示已经回文,0表示没有回文)时回文数的个数. #include <bits/stdc++.h> using namespace std; typedef long…
Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in CaoHaha's hand.As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.But now,hi…
题目链接 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which have a big secret.SF is interested in this secret and ask VS how to get it.There are the things that VS tell: Suffix(S2,i) = S2[i...len].Ni is…
题目链接 Problem Description "You shall not pass!" After shouted out that,the Force Staff appered in CaoHaha's hand. As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want. Bu…
[链接]点击打开链接 [题意] 给你一个面积,让你求围成这个面积最少需要几条边,其中边的连线只能是在坐标轴上边长为1的的线或者是两个边长为1 的线的对角线. [题解] 找规律题 考虑s[i]表示i条边能组成的最大面积. s[6]=4. s[7]=4+1.5=5.5 s[8]=4+4=8 s[9]=8+1.5=9.5 s[10]=8+4=12 s[11]=12+2.5=14.5 s[12]=12+=18 之后又重复一遍..s[13]=18+2.5,s[14]=18+6 可以发现,一开始x1 = 1…
[链接]点击打开链接 [题意] 有人写了一个最小点覆盖的贪心算法,然后,让你去hack它. 并且,要求这个算法得到的错误答案,是正确答案的三倍. 让你任意输出hack数据,点数<=500 [题解] 最小点覆盖->二分图? 程序中有这么一段 if (deg[i] >= mx) { mx = deg[i]; u = i; } 也就是说,如果有多个度数最大的,它会选择标号最大的那一个. 这就是我们构造出答案的基础. 我们可以把二分图的左右两个部分各加N个点. 然后右边的点依次标号为N+1,N+…
Problem Description "You shall not pass!" After shouted out that,the Force Staff appered in CaoHaha's hand. As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want. But now…
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=6152 [题意] 有一个队伍,如果队伍里有三个或三个以上的人互相认识 或者队伍里有三个或三个以上的人互相不认识,那么这个队伍为bad team, 否则为great team. [题解] 参考上一篇文章的求3元环做法. 只不过在两张图上进行而已. 两个递归可以合在一起写的. (不是朋友的话标记这条边为0,是朋友标记这条边为1) 在标记为0的图上做一遍,在标记为1的图上做一遍. [错的次数] 0 [反思]…
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=6156 [题意] 已知函数f(x, k),如果10进制数x在k进制下是个回文数,那么f(x, k)值为k,否则为1 现给出l, r, x, y, 求出∑∑f(i, j)  (l<=i<=r)  (x<=j<=y) [题解] 如果会求10进制的回文数个数问题的话,多少进制都能求了. 十进制L..R回文数 在这个程序的基础上把十进制改成base进制就好 剩下的不难写 [错的次数] 0 [反思]…
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=6153 [题意] ,S2中出现的次数与其长度的乘积之和.  [题解] 扩展KMP的模板题. 首先,把S2和S1都倒转一下. 这样就转化成球S2的所有前缀在S1中出现的次数了. 而扩展KMP算法可以求出S1的每个位置i它的后缀i..lens1和S2[0..lens2-1]的最长公共前缀; 因为每个起点都不一样,则不会出现重复计算. 又因为S2的开头字符一定要涉及到; 所以这样是正确的. 根据这个exten…
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6438 Buy and Resell Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1233    Accepted Submission(s): 407 Problem Description The Power Cube is used…
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 919    Accepted Submission(s): 290 Problem Description YJJ is a salesman who h…
Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migic tree, the tree has N nodes , in each node , there is a treasure, it's value is V[i], and for each edge, there is a cost C[i], which means every time…
Tree and Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 619    Accepted Submission(s): 214 Problem Description There are N vertices connected by N−1 edges, each edge has its own len…
给定的\(p\)是素数,要求给定一个加法运算表和乘法运算表,使\((m+n)^p = m^p +n^p(0 \leq m,n < p)\). 因为给定的p是素数,根据费马小定理得 \((m+n)^{p-1} \equiv 1(mod\ p)\) 因此,\((m+n)^{p} \equiv m + n\ (mod\ p)\), 同时,\(m^p + n^p \equiv m + n\ (mod\ p)\). 所以在模p意义下,\((m+n)^p = m^p +n^p(0\leq m,n < p)…
Dream Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1014    Accepted Submission(s): 200Special Judge Problem Description Freshmen frequently make an error in computing the power of a sum of r…
Tree and Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description There are N vertices connected by N−1 edges, each edge has its own length.…
Find Integer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0Special Judge Problem Description people in USSS love math very much, and there is a famous math proble…