随笔分类 -  hdu 题解

摘要:4028The time of a day题目大意:有个奇怪的钟有n(1 2 #include 3 #include 4 #include 5 typedef long long ll; 6 using namespace std; 7 mapdp[50]; 8 int n; 9 ll m;10 ll gcd(ll a,ll b)11 {12 return b==0?a:gcd(b,a%b);13 }14 ll lcm(ll a,ll b)15 {16 return a/gcd(a,b)*b;17 }18 void init()19 {20 dp[1][1]=1;2... 阅读全文
posted @ 2014-01-08 23:17 默默如潮 阅读(373) 评论(0) 推荐(0)
摘要:4022Bombing题目大意:给你n个点(二位),坐标范围( >的map x,y表示 横纵有多少个点,每次询问是返回该值就可,然后把对应的另一维的该点删除掉就可以了。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 typedef map > m; 8 m x,y; 9 int getans(m &x,m &y,int pos)10 {11 int ans = x[pos].size();12 for(multiset ::iterator i = x[ 阅读全文
posted @ 2014-01-08 22:53 默默如潮 阅读(260) 评论(0) 推荐(0)
摘要:402124 Puzzle题目意思:给你一个如上图的图,格子从左到右从上到下编号,每个格子上有数字(0~23,0表示空),操作的过程为当一个格子的上下左右有空格子时可以交换两个格子的数字。现在给你两个序列,表示的是对应编号上的数字,问能不能通过若干次操作将第一种序列变为第二个。分析:首先考虑比较特殊的几个位置即最边上的格子,可以它们只能与一个格子交换所以先预处理一下,把能交换的交换,然后判一下两个序列这些位置上的数字是不是都相同,如果不想同那么最终不可以转化。那么剩下的就是4*4的方格了,其中有一个为空,就是15数码了。根据八数码判断能不能完成我们知道与当前状态的逆序数的奇偶有关。可以发现左右 阅读全文
posted @ 2014-01-08 22:41 默默如潮 阅读(233) 评论(0) 推荐(0)
摘要:4027Can you answer these queries?两种操作:1 x y 把[x y]区间中的数变为原来数值的根号(取整)0 x y 求[x y]区间和分析:线段树 区间更新+区间求和 可增加一个标记表示该位置上的数位1或0 因为1 或0 开根号还是本身不用更新 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxlen 100010 7 typedef long long ll; 8 using namespace std; 9 struct node10 {11 int l... 阅读全文
posted @ 2014-01-08 12:11 默默如潮 阅读(195) 评论(0) 推荐(0)
摘要:hdu 1520 Anniversary party分析:要求不跟自己的上司或下属在一起即根不与其孩子同时选择。dp[i][0]表示i为根且根不选获得的最大值,则其值为孩子结点选择与不选的最大值即dp[i][0]=max(dp[son][0],dp[son][1]);dp[i][1]表示i为根且选择获得的最大值,则其孩子结点不能选择dp[i][1]=sum{dp[son][0]}; 1 #include 2 #include 3 #include 4 #define maxlen 6010 5 using namespace std; 6 struct node 7 { 8 in... 阅读全文
posted @ 2013-10-01 21:49 默默如潮 阅读(369) 评论(0) 推荐(0)
摘要:Problem DescriptionBenny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are placed in these squares. Different square has a different type of pipe. There are 11 types of pipes, which is marked from A to K, as Figure 1 shows 阅读全文
posted @ 2013-09-18 23:22 默默如潮 阅读(187) 评论(0) 推荐(0)
摘要:比赛的时候跟学长说了一下我的想法,贪心,首先排序,x从小到大排序,x相同的y从小到大,然后优先选择边长小的能组成正方形的点。但是写跪了,后来交给学长写状态压缩dp。今天看到结题报告里有人用的类似的方法过了,查看后发现是我没有判断重点的情况,改后怒ac,还是太弱了,不然可以省下点时间做其他的题目。 1 #include 2 #include 3 #include 4 #include 5 #define maxlen 30 6 using namespace std; 7 int maps[110][110]; 8 struct node 9 {10 int x,y;11 }p[... 阅读全文
posted @ 2013-09-18 14:48 默默如潮 阅读(227) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4745比赛的时候一直想的是枚举每个起点然后求最长公共子序列,一直TLE,一直优化无果。后来看到了过的人都是用最长回文子序列的算法,第一次见到这个算法,学习了。在这题中我们用dp[i][j]表示一只兔子从i逆时针走,另一只从j顺时针走,可以走到的最长距离。那么方程就是(与最长公共子序列类似)dp[i][j]=dp[(i-1+n)%n][(j+1)%n]+2 a[i]==a[j]dp[i][j]=max{dp[(i-1+n)%n][j],dp[i][(j+1)%n]} a[i]!=a[j]最后的结果就是枚举... 阅读全文
posted @ 2013-09-18 14:11 默默如潮 阅读(269) 评论(0) 推荐(0)
摘要:Problem DescriptionSome of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us.There is a large number of magnetic plates on every door. Every plat 阅读全文
posted @ 2013-08-11 19:50 默默如潮 阅读(253) 评论(0) 推荐(0)
摘要:Building BlockTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1982Accepted Submission(s): 598Problem DescriptionJohn are playing with blocks. There are N blocks (1 2 #include 3 #include 4 #define maxlen 30010 5 using namespace std; 6 int father[ma. 阅读全文
posted @ 2013-07-12 19:33 默默如潮 阅读(233) 评论(0) 推荐(0)
摘要:怪盗基德的挑战书Time Limit: 3000/1000 MS (Java/Others)Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 316Accepted Submission(s): 142Problem Description “在树最美丽的那天,当时间老人再次把大钟平均分开时,我会降临在灯火之城的金字塔前,带走那最珍贵的笑容。”这是怪盗基德盗取巴黎卢浮宫的《蒙娜丽莎的微笑》这幅画时,挑战书上的内容。 但这次,怪盗基德的挑战书上出现了一串串小写字母“aaab sdfeeddd...”。柯南以小学生的眼睛.. 阅读全文
posted @ 2013-05-19 22:28 默默如潮 阅读(260) 评论(0) 推荐(0)