自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(76)
  • 收藏
  • 关注

转载 hdu 1728 逃离迷宫 bfs

每个点加4个方向View Code #include <stdio.h>#include <string.h>#include <queue>using namespace std;struct node{ int x,y,dir,step; friend bool operator <(nod...

2012-11-04 14:16:00 91

转载 hdu 3720 Arranging Your Team dfs

思路很简单直接暴力,只是代码复杂了点View Code #include <iostream>#include <string>#include <map>#define Min -0x3f3f3f3fusing namespace std;map<string,int> m;struct nod...

2012-07-12 17:00:00 89

转载 hdu 4039 The Social Network bfs

照着题目的意思打代码就行了,这里我是用邻接表建的图。先把A的所有朋友找到(统称为B),并且标记,再去找B的朋友,如果B的朋友不是A的朋友,按字典序输出出现次数最多的。View Code #include <iostream>#include <string>#include <map>#include <queue&g...

2012-07-12 15:32:00 85

转载 hdu 4016 Magic Bitwise And Operation dfs+位运算剪枝

&的数字越多值越小,所以一直递归下去值是变小的View Code #include <stdio.h>#include <algorithm>using namespace std;int n,k;__int64 ar[50],ans;void init(){ int i; scanf("%d...

2012-07-12 10:57:00 107

转载 hdu 4235 Vampire Numbers

直接暴力,不过加了点优化:1.如果你求出50的答案是126,那么50-126的答案都是126了;2.求10的时候,只用循环到有答案的那个(比如是50)就行了,不用到126了。View Code #include <stdio.h>#include <math.h>#include <string.h>int ans[...

2012-04-26 10:37:00 72

转载 hdu 1198 Farm Irrigation dfs

View Code #include <stdio.h>int n,m,ans;int dir[4][2]={-1,0,0,-1,0,1,1,0};//上左右下int ar[12][4]={{1,1,0,0},{1,0,1,0},{0,1,0,1},{0,0,1,1}, {1,0,0,1},{0,1,1,0},{1,1,1,0},{1,1,0,1}...

2011-12-24 23:22:00 79

转载 hdu 1072 Nightmare bfs

我自己想了个嵌套的队列,就像是嵌套循环来枚举一样有多少个起点,每个起点可以走五步,如果能走到4这个点,则4这个点又可以作为起点,加入外层队列View Code #include <stdio.h>#include <string.h>#include <queue>using namespace std;struct node{ ...

2011-12-24 10:37:00 91

转载 hdu 1728 逃离迷宫 bfs

蛋疼,犯了2个错误1.不能每遇到个点都把它四个方向的每个点都走一个(每个点入一次队列),这样要mle2.不能把已经走过的点标记成‘*’,这样要waView Code #include <stdio.h>#include <queue>using namespace std;struct node{ int x,y,cnt;}a;int n...

2011-12-22 17:59:00 60

转载 hdu 1584 蜘蛛牌 dfs

自己改了很久,老是出错,最后发现在把一张牌 i 选出来放在另一张牌 j 上出了问题,但如果要改的话,就要去找牌 i 能放的唯一一张牌 j 又不方便最后不得不佩服那些把输入处理成id[x]=i;这样的人,写的很精彩。View Code #include<stdio.h>#include<math.h>int mark[11],id[11],ans;v...

2011-12-22 14:48:00 74

转载 hdu 1026 Ignatius and the Princess I bfs

用到了图论最短路更新的思想,当走到走过的地方时要更新数据:5 6.XX.1...X.6.2...X....XX.XXXXX.View Code #include <stdio.h>#include <string.h>#include <queue>using namespace std;struct node{...

2011-12-22 14:34:00 79

转载 hdu 1422 重温世界杯 dp

类似于最大子段和的做法View Code #include <stdio.h>int main(){ int i,n,a,b,sum,cnt,max,ar[100005]; while (scanf("%d",&n)!=EOF) { for (i=0;i<n;i++) { scanf...

2011-12-22 14:27:00 63

转载 hdu 1712 ACboy needs your help dp

分组背包,学习了!View Code #include <stdio.h>#include <string.h>int dp[105];int max(int a,int b){ return a>b?a:b;}int main(){ int n,m,i,j,k,ar[105][105]; while (scanf("%d%d"...

2011-12-20 17:44:00 73

转载 hdu 1180 诡异的楼梯 bfs

简单的bfs只是要注意,当楼梯不能通过的时候,可以等带它变过来,这样时间就要加1分钟(位置不变),然后把这个点重新加入队列View Code #include <stdio.h>#include <queue>using namespace std;struct node{ int x,y,t;}a;int n,m,ex,ey;char ma...

2011-12-20 17:40:00 81

转载 poj 1835 宇航员 模拟题

写的时候思路很清晰,以面对的方向和它的右边为标准,这样写24个方向出来,不过代码量太大了,后来看了别人的思路后,原来可以写的这么简短!不过还是纪念下自己这个又臭又长的代码吧..View Code #include <stdio.h>#define x1 0#define y1 1#define z1 2#define x2 3#define y2 4#defi...

2011-12-15 23:20:00 149

转载 hdu 1559 最大子矩阵 枚举

枚举的思路,只是利用了行压缩来优化View Code #include <stdio.h>#include <string.h>int map[1005][1005],ar[1005];int main(){ int T,m,n,x,y,i,j,k,sum,ans; scanf("%d",&T); while (T--) ...

2011-12-15 21:17:00 62

转载 hdu 1243 反恐训练营 dp

简单的最长公共子序列的变形,只是题有点吓人..View Code #include <stdio.h>#include <string.h>int dp[2005][2005],ar[2005];int max(int x,int y){ return x>y?x:y;}int main(){ int n,a,len1,len2,i,...

2011-12-15 21:13:00 93

转载 poj 1840 Eqs 二分

把a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 变换成 a1x13+ a2x23+ a3x33=—( a4x43+ a5x53 )这步很重要。这样这个题就变成了,在一个很大的数组里,查找一个数是否存在,存在的话有几个?View Code #include <stdio.h>#include <algorithm>using...

2011-12-02 11:40:00 72

转载 poj 3768 Repeater 递归

由poj 2083想到,从坐标(1,1)到(x,y)都是有公式的,所以只需给每个地方找到对应的公式就好了View Code #include <stdio.h>#include <math.h>#include <string.h>int p;char ch,map[3005][3005],ans[30][30];void dfs(int ...

2011-12-02 11:33:00 98

转载 poj 1941 The Sierpinski Fractal 递归

注意这个道题的行和列,别混乱了View Code #include <stdio.h>#include <string.h>#include <math.h>char map[3000][3000];void dfs(int n,int x,int y){ int size; if(n==1) { map[x...

2011-12-02 11:27:00 99

转载 poj 2083 Fractal 递归

今天一共做了3道分形的题,开始没弄对,后面明白解题思想是从1个地方变到n个地方,就很简单了。View Code #include <stdio.h>#include <math.h>int n;char map[1000][1000];void dfs(int n,int x,int y){ int size; if(n==1) { ...

2011-12-02 11:25:00 90

转载 poj 1170 Shopping Offers 记忆化dfs

剪枝:当前状态已经存在了,它一定是最优值,直接返回它View Code #include <stdio.h>#define inf 0x3f3f3f3fstruct node{ int num[1000],price;}ar[105];int s,n,a[10],num[1000];int dp[6][6][6][6][6];int min(int x,in...

2011-11-30 20:11:00 84

转载 poj 2530 Tetris Alphabet 模拟

思路:按列循环,来模拟去方格的过程View Code #include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char str[55][25],tmp[55][25],ans[27];int n,flag;int judge(int x,int...

2011-11-28 19:36:00 92

转载 poj 2472 106 miles to Chicago floyd

View Code #include <stdio.h>#include <string.h>int n,m;double map[105][105];void floyd(){ int i,j,k; for (i=1;i<=n;i++) { for (j=1;j<=n;j++) { ...

2011-11-26 21:06:00 103

转载 poj 2497 Strategies 模拟

提供一组数据:输入: 2 30 1 10 0 1 10输出: Scenario #1:Steve wins with 1 solved problems and a score of 10.Scenario #2:Steve wins with 0 solved problems and a score of 0.View ...

2011-11-26 21:01:00 70

转载 poj 2457 Part Acquisition dij

dij+记录路径View Code #include <stdio.h>#define inf 0x3f3f3f3fint k,n,path[1005],dis[1005],map[1005][1005];void dij(){ int i,j,min,minj,vis[1005]; for (i=1;i<=k;i++) { ...

2011-11-26 20:55:00 47

转载 poj 2499 Binary Tree

思路:此题的数据规模太大了,肯定不能去递归,最后想到下面这个办法由结果(s,e)向(1,1)推,如果s>e,s-=e;如果s<e,e-=s;但是由于数据太大了,减法要超时,所以改成除法就行了View Code #include <stdio.h>int main(){ int n,s,e,left,right,l=1,a; scanf(...

2011-11-25 22:06:00 56

转载 poj 2456 Aggressive cows 二分

最小的最大View Code #include <stdio.h>#include <algorithm>using namespace std;int n,c,ar[100005];void f(){ int left,right,mid,num,now,ans,i; left=0,right=ar[n-1]-ar[0]; whil...

2011-11-25 21:58:00 77

转载 poj 2436 Disease Management 枚举

思路:有D种病毒,就有2^D种选法,当选出的病毒数为K时,就遍历这N头牛,如果有牛所携带的病毒包含在K这些病毒里面,m++;View Code #include <stdio.h>int n,d,k,Max,vis[20],a[1005][20];void f(){ int i,j,m=0; for (j=0;j<n;j++) { ...

2011-11-25 21:53:00 83

转载 poj 2421 Constructing Roads 最小生成树

把已经有的边,加入到图中,再用克鲁斯卡尔算最小生成树简单的一道题,但是我居然把输出看错意思了....View Code #include <stdio.h>#include <algorithm>using namespace std;struct node{ int s,e,len;}map[5055];int k,f[105];int c...

2011-11-24 16:50:00 76

转载 poj 2803 Defining Moment 模拟

View Code #include <stdio.h>#include <string.h>int start,end;char s[105];void p(){ int i=0; for (i=start;i<=end;i++)printf("%c",s[i]);}int main(){ int n,i,j,k,l,pre_an...

2011-11-23 20:30:00 72

转载 poj 2418 Hardwood Species 排序二叉树

题意:有n个单词,要求每个单词出现的频率(次数/n),并把这些单词以字典序输出View Code #include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;struct Tree{ int ...

2011-11-23 20:28:00 79

转载 poj 2876 Cantoring Along 递归

View Code #include <stdio.h>#include <string.h>#include <math.h>char ans[1000000];void dfs(int s,int e){ int i,len; if(e-s==1) { ans[s]='-'; return; ...

2011-11-18 20:01:00 72

转载 poj 2255 Tree Recovery 递归

View Code #include <stdio.h>#include <string.h>char pre[30],ino[30],ar[100000];int len;void T(int k,int s,int e,int now){ int i; if(s>e)return; ar[now]=pre[k]; for(...

2011-11-18 20:00:00 50

转载 poj 1555 Polynomial Showdown

注意:1.开头系数是负的话,负号后面没有空格;如果是正的话,不输出正号和空格2.系数是1的话,不输出1;如果是-1的话,也不输出13.指数是1的话,不输出^14.最后一位,不输出x^0View Code #include <stdio.h>int ar[10],i;void solve(int j){ if(ar[i]!=0) { ...

2011-11-16 21:28:00 123

转载 poj 1598 Excuses, Excuses! trie

思路:把所有的单词存到字典树中,然后把句子中的字母全改成小写的,就剥离句子中的单词,在字典树中查找View Code #include <iostream>#include <string.h>#include <stdio.h>using namespace std;struct trie{ int flag; char...

2011-11-16 18:52:00 75

转载 poj 1505 Copying Books 二分

二分的时候左边的初始值弄错了,一直wa.5 31 1 1 1 101 / 1 1 1 / 10View Code #include <stdio.h>int m,n,k,a,ar[505];void solve(int mid){ int i,j,s=0; for (i=0;i<n;i++) { if(ar[i]+...

2011-11-16 13:42:00 81

转载 poj 3991 Seinfeld

我的做法是,用栈把能stable的去掉,把剩下的左空号和右括号的个数分别算出来n,m,n和m肯定同奇同偶如果是偶数的话,}}{{——>{}{},2次操作:n/2+m/2;如果是奇数的话,}}}{——>{}{},3次操作:(n-1)/2+(m-1)/2+2;View Code #include <stdio.h>#include <stri...

2011-11-14 13:26:00 67

转载 poj 1837 Balance dp

0-1背包真是没想到..View Code #include <stdio.h>int dp[25][15005];int main(){ int C,G,i,j,k,c[25],g[25]; scanf("%d%d",&C,&G); for (i=0;i<C;i++)scanf("%d",&c[i]); ...

2011-11-14 10:43:00 74

转载 poj 2336 Ferry Loading II dp

if(a>dp[i-j])dp[i]=min(dp[i],2*t+a); else dp[i]=min(dp[i],2*t+dp[i-j]);dp[i]表示第i个车到达对岸花的最少时间由于第 i 个车可以和它前面的 j(1~n-1)个车一起坐船,所以可以得到dp[i]=min(dp[i],dp[i-j]+2*t);但是第 i 个车到达的时间可能大于了dp[i-j],这样...

2011-11-12 19:38:00 91

转载 poj 2593 Max Sequence dp

抱着试试的态度,居然1A了..方法就是,正向和反向各求一次连续子段和,并且把每达到的位置的最大和保存起来ans=max(ans,sum1[i]+sum2[i+1]);sum1[i]表示第i个数前面的最大连续子段的和,sum2[i+1]表示从i+1个数后面的最大连续子段和View Code #include <stdio.h>int ar[100005]...

2011-11-12 13:20:00 91

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除