04 2013 档案

摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1735思路:贪心,只要开头有两个0,则需要判断其上一行最后有多少个连续的0,按上一行最后处0的数量由大到小排序(特殊处理一下最后一行末尾0就可以了);View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define MAXN 10000+10 7 #define MAXL 阅读全文
posted @ 2013-04-30 22:50 ihge2k 阅读(464) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1572思路:dfs暴搜即可。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 #define MAXN 33 6 #define inf 1<<30 7 int map[MAXN][MAXN]; 8 int n,MIN,k; 9 int num[MAXN];10 bool mark[MAXN];11 12 void 阅读全文
posted @ 2013-04-30 21:58 ihge2k 阅读(335) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1707思路:memset妙用,把当天的上课时间标记为true..然后查询的时候进行遍历就行了。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cstdlib> 6 using namespace std; 7 #define MAXN 222 8 struct Person{ 9 bo 阅读全文
posted @ 2013-04-30 21:18 ihge2k 阅读(207) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1497思路:就是一个简单的图书管理系统模拟,book的布尔值显示是否在图书馆;如果有一个人还书,那么那个人的拥有书的信息也要修改。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define MAXN 100000+10 7 bool book[MAXN]; 8 in 阅读全文
posted @ 2013-04-30 20:26 ihge2k 阅读(284) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1571思路:纯模拟,vector的应用。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<vector> 5 using namespace std; 6 #define MAXN 33 7 int map[MAXN][MAXN]; 8 int n; 9 10 int main(){11 while(~scanf("%d" 阅读全文
posted @ 2013-04-30 17:17 ihge2k 阅读(175) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1409思路:就是把所有的不符点条件都排除掉,如果都符合,就Yes,否则,No;View Code 1 #include<cstdio> 2 #include<cstring> 3 4 int main(){ 5 int _case; 6 scanf("%d",&_case); 7 getchar(); 8 while(_case--){ 9 char str[110];10 gets(str);11 int cnt1... 阅读全文
posted @ 2013-04-30 16:46 ihge2k 阅读(169) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://www.codeforces.com/problemset/problem/1/B特别有用的一个处理字符串的函数(当然比不上正则表达式的强大)sscanf,直接提取数字,解题相当方便。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<string> 6 #include<algorithm> 7 using namespace std; 8 9 void 阅读全文
posted @ 2013-04-30 09:00 ihge2k 阅读(206) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1270思路:我们知道排序后sum[1]==num[1]+num[2];sum[2]==num[1]+num[3];但是num[2]+num[3]的值是不确定的,因此我们需要i(3,m)枚举,然后求出num[3]之后,将num[1]+num[2],num[1]+num[3],num[2]+num[3]的值标记,对于要求的num[4],在sum[]中的一个没有被标记过的一定是num[1]+num[4]的值,求出num[4]之后,在对num[1]+num[4],num[2]+num[4]....进行标记( 阅读全文
posted @ 2013-04-29 22:45 ihge2k 阅读(434) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1496思路:一开始没想到加1000010来避免负数,orz....直接加负数就不用分类讨论了。View Code 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int MAXN=2000100; 8 int mark[MAXN]; 9 10 11 int main(){12 int num[4];13 while(~scanf("%d",&num[ 阅读全文
posted @ 2013-04-29 20:29 ihge2k 阅读(264) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.fzu.edu.cn/contest/problem.php?cid=129&sortid=2思路:一开始思路有点混乱,然后仔细一看数据,发现暴力即可。View Code 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int MAXN=50005; 7 char s3[MAXN]; 8 int num[MAXN]; 9 10 int main(){11 char s1[110],s2[110];12 while(gets(s1)){13 ... 阅读全文
posted @ 2013-04-29 19:23 ihge2k 阅读(210) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1423思路:dp[i][j]表示序列1(1-i)和序列2(1-j)最长的公共子序列View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=550; 7 int dp[MAXN][MAXN]; 8 int num1[MAXN]; 9 int num2 阅读全文
posted @ 2013-04-29 19:19 ihge2k 阅读(666) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://ac.nbutoj.com/Problem/view.xhtml?id=1409思路:一道不错的题,递推关系式之后还得处理大数。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 using namespace std; 7 const int MAXN=110; 8 int dp1[MAXN][MAXN],dp2[MAX 阅读全文
posted @ 2013-04-27 22:08 ihge2k 阅读(209) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1306思路:一开始还以为是求最长公共序列呢。。。仔细一看,orz.....就是求两个串匹配时公共部分字符最多相同的个数。。。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 int gcd(int a,int b){ 9 return a%b==0?b:gcd(b,a%b);10 }11 12 13 int m... 阅读全文
posted @ 2013-04-26 18:25 ihge2k 阅读(513) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2832坑爹的精度损失。。。。orz。。。。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 8 9 int main(){10 double n;11 while(~scanf("%lf",& 阅读全文
posted @ 2013-04-26 13:01 ihge2k 阅读(198) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1302思路:直接按着题目意思模拟就行了。。。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cmath> 5 using namespace std; 6 7 int main(){ 8 double h,u,d,f; 9 while(~scanf("%lf",&h)&&h){10 阅读全文
posted @ 2013-04-26 12:28 ihge2k 阅读(673) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1296不知为什么今天人品特别好。。。1Y....不过又去搜了一下别人的代码。。。orz。。。我的渣代码啊。。。还是贴一下吧。。。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstring> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespac 阅读全文
posted @ 2013-04-25 22:41 ihge2k 阅读(357) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1237思路:模拟栈,先处理*和/的,算出结果后在入栈,将‘+’和‘-’入s栈,最后由于考虑加减运算符的优先级,还有倒一下栈。。这样就一共用到了4个栈。。。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<stack> 7 usi 阅读全文
posted @ 2013-04-25 13:12 ihge2k 阅读(817) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1172思路:一开始看这道题的时候觉得没什么思路。。。暴搜吗????然后仔细分析了一下,觉得不行。。。然后网上搜了一下。。。orz。。。枚举啊!!!把最基本的给忽略了。。。好吧,就是枚举1000-9999之间的数,然后把每个数都与给定的几个数以及条件进行比较,如果都符合,那么就记录个数。。。最后,看有多少个数满足条件。。。题目的意思是说只有一个数满足条件。。。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 阅读全文
posted @ 2013-04-24 18:44 ihge2k 阅读(998) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.whu.edu.cn/land/problem/detail?problem_id=1478比赛的时候由于对题意不是很理解,当时就不想写这道题。。。orz。。。然后回来的时候队友用string写了一个TLE,然后我也搞了一下。无奈TLE到死啊!!!!这不知道我们还有一直队用string是怎么过的。。。orz..........看完解题报告。我傻眼了。。。就是模拟链表啊!!!!好吧。。。。见识短了。。。。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include 阅读全文
posted @ 2013-04-23 21:32 ihge2k 阅读(191) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050思路:就是跟hdu2037那题差不多,可不知道为什么一开始我按结束区间的大小排序就wa了,然后改成按开始区间的大小排序就ac了。。。不明白了,还请大牛解释。。。orzView Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<algori 阅读全文
posted @ 2013-04-20 19:47 ihge2k 阅读(236) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3172思路:将名字转化为对应的序号就可以,然后就是基本的并查集操作了。。。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<map> 6 #include<string> 7 using namespace std; 8 const int MAXN=100000 阅读全文
posted @ 2013-04-20 10:50 ihge2k 阅读(421) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2473思路:就是每次删除节点的时候并不是把节点删除,而是单独成一个集合。。。以前不知道为什么每次做并查集的时候,总是TLE。。。今天终于是找到原因了,然后找出来以前TLE的代码,然后一个就过了。。。不多说了,具体见代码:View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int MAXN=1000000 阅读全文
posted @ 2013-04-19 21:05 ihge2k 阅读(422) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829思路:就是同性别的合并在一个集合中,然后每次输入看u,v是否在同一个集合中。。。然后不知道为什么用路径压缩不可以写。。。一些就TLE了。。。无语了。。。orz。。。View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 using namespace std; 6 const int MAXN=2000+ 阅读全文
posted @ 2013-04-18 18:11 ihge2k 阅读(314) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1811思路:先处理‘=‘,全部合并为同一个节点,然后在拓扑排序就可以了。。。拓扑排序知识:*如果一次入队入度为零的点大于1则说明拓扑排序序列不唯一*如果排序的总个数小于给定的个数,则说明存在回路View Code 1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<vector> 6 #inclu 阅读全文
posted @ 2013-04-18 16:49 ihge2k 阅读(521) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1116思路:先合并,然后判断根结点是否唯一,如果是,则在判断是否是欧拉路;否则,直接结束。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int MAXN=100000+10; 6 int In[MAXN],Out[MAXN]; 7 int parent[MAXN]; 8 bool mark[MAXN]; 9 i 阅读全文
posted @ 2013-04-17 20:49 ihge2k 阅读(194) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3986思路:先spfa求出最短路,然后枚举删除最短路上的边,每次删除一条边,就求一次最短路,然后去最大的那个就行了。。。可以重边的问题没考虑完善,wa了好多次啊!!!View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<vector> 5 using namespace std; 6 const int MAXN=1000+10; 7 const i 阅读全文
posted @ 2013-04-17 20:49 ihge2k 阅读(373) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3191题意:求出次短路的长度和条数View Code 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int MAXN=55; 8 const int inf=1vet[MAXN]; 13 struct Node{ 14 int v,dist; 15 int mark;//标记,1为最短路,2为次短路; 16 bool operator... 阅读全文
posted @ 2013-04-16 22:16 ihge2k 阅读(605) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962思路:二分枚举高度,每次都sfpa一下,然后如果dist[e]存在的话,就更新shortpath...View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<vector> 5 #include<algorithm> 6 const int MAXN=1000+10; 7 const int inf=1<<30; 8 us 阅读全文
posted @ 2013-04-15 22:27 ihge2k 阅读(301) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2377思路:对每个点spfa求一次最短路,每次求的时候都要用一个MAX_dist[]来保存当前点到各点的最短路径的最大值,然后这个数组中的min值就是star value了。。。View Code 1 #include<iostream> 2 #include<queue> 3 #include<vector> 4 const int MAXN=10000+10; 5 const int inf=1<<30; 6 using namespace std 阅读全文
posted @ 2013-04-14 20:30 ihge2k 阅读(247) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2363思路:和之前hdu上做过的一题很像。。。就是先求求出所有的高度差,排序后枚举,每次都一次spfa,求出dist,若dist[n]!=inf,说明是在最小高度差下找到了最短路径,直接break即可。。。另外,发现若不用visited[]标记的话,时间是其两倍。。。orz....以后还是老老实实加visited [] 吧。。。View Code 1 #include<iostream> 2 #include<queue> 3 #include<vector> 4 阅读全文
posted @ 2013-04-14 20:30 ihge2k 阅读(219) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2145思路:题目很简单。。。关键是思想,如果你建图求的是每个点到终点的最短距离,那就TLE了,但仔细一想,我也可以建反向图啊!!!然后一次Dijkstra或者spfa就可以了。。。最后排序即可。View Code 1 #include<iostream> 2 #include<queue> 3 #include<vector> 4 #include<algorithm> 5 const int MAXN=333; 6 const int inf=1&l 阅读全文
posted @ 2013-04-14 10:16 ihge2k 阅读(244) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1839思路:先给容量从大到小排序,然后二分,每次都一次spfa一下,判断当前的cost[n]的值。。。View Code 1 #include<iostream> 2 #include<queue> 3 #include<vector> 4 typedef long long ll; 5 const int MAXN=10000+10; 6 const ll inf=1e60; 7 using namespace std; 8 struct Node{ 9 int 阅读全文
posted @ 2013-04-13 23:01 ihge2k 阅读(391) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1317思路:只要在SPFA中将一个条件,就不会进入负环。那么如果有正环呢,显然退出条件是某个点入队列次数>=n,此时退出时只需判断当前点是否与n存在路径,这步可以用Floyd来实现。。。View Code 1 #include<iostream> 2 #include<queue> 3 const int MAXN=110; 4 using namespace std; 5 int n; 6 int weight[MAXN]; 7 int power[MAXN]; 8 阅读全文
posted @ 2013-04-13 17:43 ihge2k 阅读(946) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1245思路:建图,0点为湖心,n+1点为湖外,然后bfs就可以了。。。具体见代码。View Code 1 #include<iostream> 2 #include<cmath> 3 #include<queue> 4 #define p 1e-7 5 const int inf=1<<30; 6 const int MAXN=110; 7 using namespace std; 8 double dist[MAXN][MAXN]; 9 double 阅读全文
posted @ 2013-04-13 16:20 ihge2k 阅读(227) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1286数学题真的是有点吃不消了。。。View Code 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 //可以快速求出欧拉函数的值 ( P为N的质因子 ) 5 //若(N%P==0 && (N/P)%P==0) 则有:E(N)=E(N/P)*P; 6 //若(N%P==0 && (N/P)%P!=0) 则有:E(N)=E(N/P)*(P-1); 7 8 //欧拉公 阅读全文
posted @ 2013-04-12 22:04 ihge2k 阅读(191) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1250思路:一开始用的是vet来保存的,速度太慢。。然后用二维数组来保存,每8位保存在数组中,处理一下进位就可以了。。。View Code 1 #include 2 using namespace std; 3 int num[10010][300];//num[i][j]存8位 4 5 6 void Initiate(){ 7 num[1][1]=1; 8 num[2][1]=1; 9 num[3][1]=1;10 num[4][1]=1;11 for... 阅读全文
posted @ 2013-04-11 20:17 ihge2k 阅读(203) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3639思路:先按一般的思路来,把杂乱的有向图通过缩点变成有向无环图,然后建反向图,并标记每个点的入度(最大值一定在反向图的入度为的点中)然后dfs一下下就可以了,最后就是在原图中找等于MAX的点就可以了。View Code 1 #include 2 #include 3 #include 4 const int MAXN=5000+10; 5 using namespace std; 6 vectormp1[MAXN];//原图 7 vectormp2[MAXN];//反向图 8 ... 阅读全文
posted @ 2013-04-10 20:46 ihge2k 阅读(704) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2208思路:应用了并查集的思想,具体见注释;View Code 1 #include<iostream> 2 const int MAXN=14; 3 using namespace std; 4 bool map[MAXN][MAXN]; 5 int root[MAXN]; 6 int N,M; 7 8 //n为当前的点,m为目前的气球数目 9 bool dfs(int n,int m){10 if(m>M)return false;11 if(n==N)return true. 阅读全文
posted @ 2013-04-10 18:18 ihge2k 阅读(245) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1269View Code 1 #include 2 #include 3 #include 4 const int MAXN=10000+10; 5 using namespace std; 6 vectormp[MAXN]; 7 stackS; 8 int n,m; 9 int _count;10 int cnt;11 bool mark[MAXN];12 int dfn[MAXN];13 int low[MAXN];14 15 //求强连通分量tarjan16 void Tarjan(int . 阅读全文
posted @ 2013-04-09 22:46 ihge2k 阅读(497) 评论(0) 推荐(0) 编辑
摘要:贴几道记忆化搜索的题。。。题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078View Code 1 #include 2 const int MAXN=110; 3 using namespace std; 4 int dp[MAXN][MAXN]; 5 int map[MAXN][MAXN]; 6 int n,m; 7 int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; 8 9 int dfs(int x,int y){10 if(dp[x][y])return dp[x][y];11 ... 阅读全文
posted @ 2013-04-09 14:14 ihge2k 阅读(249) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4540View Code 1 #include<iostream> 2 const int inf=1<<30; 3 using namespace std; 4 int map[22][22]; 5 int dp[22][22];//表示前i个时刻在第j个位置时的最小消耗能量 6 int n,m; 7 8 int main(){ 9 while(~scanf("%d%d",&n,&m)){10 for(int i=1;i<=n;i+ 阅读全文
posted @ 2013-04-08 20:00 ihge2k 阅读(358) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2452http://acm.hdu.edu.cn/showproblem.php?pid=1501记忆化搜索。。。说的简单点,就是dfs+状态标记。。。View Code 1 #include 2 #include 3 const int MAXN=10000+10; 4 const int inf=1mp[MAXN]; 8 int value[MAXN]; 9 int In[MAXN],Out[MAXN];10 int dp[MAXN][2];11 12 int dfs(int now,int . 阅读全文
posted @ 2013-04-08 08:18 ihge2k 阅读(228) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1224我感觉就是求最长上升上升序列View Code 1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 const int MAXN=110; 5 int n,m; 6 int dp[MAXN]; 7 int value[MAXN]; 8 int path[MAXN]; 9 bool map[MAXN][MAXN];10 11 void Print(int u){12 if(u==-1)retu 阅读全文
posted @ 2013-04-08 08:15 ihge2k 阅读(292) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709数位dp...完全看大牛模版理解的。。。。View Code 1 #include<iostream> 2 using namespace std; 3 __int64 dp[19][19][2000]; 4 int digit[19]; 5 6 //pos表示当前的位置,o表示支点,pre表示从最高位到pos的力矩之和,doing表示是否有上限,若无,则为9; 7 __int64 dfs(int pos,int o,int pre,bool doing){ 8 if(pos==- 阅读全文
posted @ 2013-04-07 20:50 ihge2k 阅读(696) 评论(0) 推荐(1) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3732思路:这么大的数据,用01背包肯定会TLE的,01背包转多重背包。。最多也就11*11=121件物品。。。View Code 1 #include<iostream> 2 using namespace std; 3 int dp[10010]; 4 int map[14][14]; 5 int n,m; 6 7 void CompletePack(int value,int cost){ 8 for(int j=cost;j<=m;j++){ 9 dp[j]=ma... 阅读全文
posted @ 2013-04-06 21:11 ihge2k 阅读(314) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3999思路:创建一颗二叉排序树,直接先序遍历即可。View Code 1 #include 2 using namespace std; 3 bool first; 4 5 struct BST{ 6 int data; 7 BST *leftchild; 8 BST *rightchild; 9 };10 11 void Build(BST *&root,int x){12 if(root==NULL){13 root=(BST *)malloc... 阅读全文
posted @ 2013-04-06 11:38 ihge2k 阅读(342) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1426思路:dfs搜索(回溯),有个小技巧,就是行、列的表示,具体见代码。。View Code 1 #include<iostream> 2 using namespace std; 3 bool flag; 4 int map[10][10]; 5 int row[10][10]; 6 int line[10][10]; 7 struct Matrix{ 8 bool num[10]; 9 }mat[4][4];//小的九宫格10 11 12 void dfs(int _count){ 阅读全文
posted @ 2013-04-06 09:47 ihge2k 阅读(298) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247思路:用字典树插入所有单词后直接枚举每个单词的每个分割点每个分割点的位置都入栈),然后再依此出栈判断此分割点分成的两个字符串是否都存在即可,如果所有的情况都不存在,返回false,否则,返回true... 阅读全文
posted @ 2013-04-05 17:48 ihge2k 阅读(184) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075wa了好多次啊。。。心都碎了。。。然后不知道怎么一改就对了。。。orz...建树的的时候每个单词的的最后一个结点应该加入译文的信息。。。islower()用于判断小写字母很好用。。。View Cod... 阅读全文
posted @ 2013-04-05 16:36 ihge2k 阅读(424) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1420题目很简单,暴力1A,可应该有更好的方法。。。搜了一下,可以用快速幂。。。我怎么没想到呢。。。如果数据强一点。。估计我又要跪了。。。orz..View Code 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 5 __int64 Pow(__int64 a,__int64 b,__int64 c){ 6 __int64 p=1,q=a; 7 while(b){ 8 if(b&1).. 阅读全文
posted @ 2013-04-05 10:45 ihge2k 阅读(194) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1528题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1962思路:求二分图的最小覆盖,最小覆盖=最大匹配;建图略麻烦。。。View Code 1 #include<iostream> 2 const int MAXN=30; 3 using namespace std; 4 int n; 5 bool map[MAXN][MAXN]; 6 int lx[MAXN],ly[MAXN]; 7 bool mark[MAXN]; 8 9 int d 阅读全文
posted @ 2013-04-04 21:54 ihge2k 阅读(253) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068思路:最大独立集 == |P| 减 【最大匹配(双向建图)】/2还是用的vector建邻接表。。。速度比较快。。。View Code 1 #include<iostream> 2 #include<vector> 3 const int N=507; 4 using namespace std; 5 int lx[N],ly[N]; 6 bool mark[N]; 7 vector<int>map[N]; 8 int n; 9 10 int dfs(int 阅读全文
posted @ 2013-04-04 17:44 ihge2k 阅读(202) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054思路:最小顶点覆盖 == 最大匹配(双向图)/2。。。不过一开始是用邻接矩阵,傻傻的TLE。。。然后搞了个vector,建立邻接表。。。View Code 1 #include<iostream> 2 #include<vector> 3 const int MAXN=1507; 4 using namespace std; 5 int n; 6 bool mark[MAXN]; 7 int lx[MAXN],ly[MAXN]; 8 vector<int>m 阅读全文
posted @ 2013-04-04 16:15 ihge2k 阅读(305) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712思路:这是一道简单的分组背包,因为每种课可以有多种选择:花几天时间在该课上。一旦作出选择,就不能再选该课,就相当于有多组物品,每组内的物品互相冲突,最多只能选一件。伪码:for 所有的组k for v=V..0 for 所有的i属于组k f[v]=max{f[v],f[v-c[i]]+w[i]}View Code 1 #include<iostream> 2 const int MAXN=110; 3 using namespace std; 4 i... 阅读全文
posted @ 2013-04-04 11:31 ihge2k 阅读(184) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068感觉这篇博客写的不错:http://www.felix021.com/blog/read.php?2040我就直接上代码了。。。View Code 1 #include 2 #include 3 const int N=110010; 4 using namespace std; 5 int len; 6 int p[Ni){17 p[i]=min(p[(idmx){22 mx=p[i]+i;23 id=i;24 ... 阅读全文
posted @ 2013-04-04 10:33 ihge2k 阅读(184) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1723思路:dp,不多说了,说多了都是泪啊。。。View Code 1 #include<iostream> 2 const int N=77; 3 using namespace std; 4 5 int main(){ 6 int n,m; 7 while(~scanf("%d%d",&n,&m)){ 8 if(n==0&&m==0)break; 9 int dp[N];10 memset(dp,0,sizeof(dp));11.. 阅读全文
posted @ 2013-04-03 22:14 ihge2k 阅读(186) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2813思路:用STL的map把字符串映射为序号。。。差点就超时了。。。orz。。。弱渣不敢写字典树啊!!!View Code 1 #include<iostream> 2 #include<map> 3 #include<string> 4 const int MAXN=222; 5 const int inf=1<<30; 6 using namespace std; 7 int n,m,k; 8 int match[MAXN]; 9 int lx[ 阅读全文
posted @ 2013-04-03 21:17 ihge2k 阅读(273) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2282思路:建图很重要,一个二分图最优匹配的题目。如果我们要移动巧克力,最后一定是把盒子中多余的巧克力移到空盒子中去,那么我们不妨以多出的每个巧克力以及每个空盒子为研究对象,这样每个巧克力只能放到一个空盒子中,每个空盒子也只能放一个巧克力,于是就可以构成一个二分图去求最优匹配了,其中边权为巧克力和空盒子的最短距离。View Code 1 #include<iostream> 2 const int MAXN=507; 3 const int inf=1<<30; 4 usin 阅读全文
posted @ 2013-04-03 17:59 ihge2k 阅读(246) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3718思路:题目求的是两字符串的最大相似度思路:因为第一个串的一种字母只能匹配第二个串的一种字母,所以可以转化为求【字母的最大匹配值/n】建图:【例】View Code 1 #include<iostream> 2 #include<string> 3 const int MAXN=30; 4 const int inf=1<<30; 5 using namespace std; 6 int match[MAXN]; 7 int lx[MAXN],ly[MAXN] 阅读全文
posted @ 2013-04-03 09:00 ihge2k 阅读(296) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3488思路:KM算法求最小权。。。ps:任何完全图的二分匹配其实就是n个环的并View Code 1 #include<iostream> 2 const int MAXN=222; 3 const int inf=1<<30; 4 using namespace std; 5 int n,m; 6 int map[MAXN][MAXN]; 7 int lx[MAXN],ly[MAXN]; 8 int match[MAXN]; 9 bool visitx[MAXN],visi 阅读全文
posted @ 2013-04-02 22:35 ihge2k 阅读(553) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1853二分匹配,求最小权,只要一开始先取相反数,lx初始化的时候取无穷小。。。然后KM一敲,最后输出在取相反数就行了。。。值得一提的是,我这种渣代码,竟然跑了个rank 1。。。orz。。。View Code 1 #include<iostream> 2 const int MAXN=110; 3 const int inf=1<<30; 4 using namespace std; 5 int n,m; 6 int map[MAXN][MAXN]; 7 int lx[MAX 阅读全文
posted @ 2013-04-02 21:33 ihge2k 阅读(247) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1533题意:给你一个N行M列的矩阵,其中“.”代表空地,“H”代表房子,“m”代表人,其中有n个房子和n个人。现在要求每个人进入一间房子,且人走一步需要支付1美元。求最小需要花费多少美元才能让所有人都进入到房子中(每个人只能进入一间房子,每个房子只能容纳一个人)。思路:就是一个二分图最优匹配的变形,所以说建图很重要啊!!!(把‘m'的坐标计入到X集,’H‘的坐标计入到Y集)在建图的时候,将每条边的权值变为负数。然后lx[i]初始化为-inf,结果输出-ans,就可以得到最小权值View Co 阅读全文
posted @ 2013-04-02 18:31 ihge2k 阅读(631) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2853思路:因为我们要变动最小,所以对在原计划中的边要有一些特殊照顾,使得最优匹配时,尽量优先使用原计划的边,这样变化才能是最小的且不会影响原匹配。根据这个思想,我们可以把每条边的权值扩大k倍,k要大于n。然后对原计划的边都+1。精华全在这里。我们来详细说明一下。全部边都扩大了k倍,而且k比n大,这样,我们求出的最优匹配就是k倍的最大权值,只要除以k就可以得到最大权值。实现原计划的边加1,这样,在每次选择边时,这些变就 有了优势,就会优先选择这些边。假如原计划的h条边被选入了最优匹配中,这样,最优权 阅读全文
posted @ 2013-04-02 16:55 ihge2k 阅读(219) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795思路:数组只要开min(h,n)大小就行了。。。线段树最后一层存的是每行的剩余量,然后父节点存当前子树中最大连续空余。View Code 1 #include 2 const int MAXN=200007; 3 using namespace std; 4 int h,w,n; 5 int MAX[MAXN>1;15 Build(l,m,rt>1;25 int ret=(MAX[rt=x)?Query(x,l,m,rtn)h=n;34 Build(1,h,1... 阅读全文
posted @ 2013-04-01 18:45 ihge2k 阅读(220) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394思路:求最小的逆序数。。。可以暴力,也可以用线段树来做。。。下面是用线段树实现的代码:View Code 1 #include 2 const int MAXN=5007; 3 using namespace std; 4 int sum[MAXN>1;27 if(p>1;37 int ret=0;38 if(Lm)ret+=query(L,R,m+1,r,rt<<1|1);40 return ret;41 }42 43 44 int main(){45 ... 阅读全文
posted @ 2013-04-01 17:17 ihge2k 阅读(203) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示