上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 30 下一页
  2012年10月13日
摘要: 大意;求在最小的交换次数的情况下使得序列升序排列的方案数。思路:冒泡排序对应最小交换数,然后回溯。CODE:#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>usingnamespacestd;intans;intn;inta[1001];intcheck(int*a){for(inti=0;i<n-1;i++){if(a[i]>a[i+1])return0;}return1;}voidswap(int&a,int&b){intt=a 阅读全文
posted @ 2012-10-13 12:40 有间博客 阅读(187) 评论(0) 推荐(0) 编辑
摘要: BFS+hash判重。CODE:(TLE)#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<queue>#include<set>usingnamespacestd;typedefintState[9];constintMAXN=1000003;constintdx[]={-1,1,0,0};constintdy[]={0,0,-1,1};chardir[5]="udlr";intgoal[9]={1 阅读全文
posted @ 2012-10-13 09:50 有间博客 阅读(407) 评论(0) 推荐(0) 编辑
  2012年10月12日
摘要: 大意:八数码问题的变形,让你求离当前状态最远的距离。思路:BFS + hash判重,直到不能扩展为止,最后一个节点一定是最远的距离(由BFS性质知道)CODE:#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<queue>#include<set>usingnamespacestd;typedefintState[9];constintMAXN=1000003;constintdx[]={-1,1,0,0};consti 阅读全文
posted @ 2012-10-12 21:38 有间博客 阅读(271) 评论(0) 推荐(0) 编辑
  2012年10月11日
摘要: 隐式图的遍历。大意:在5X5方格中,给你一定的棋子,让你判断找出最小的步数变成给定的状态。思路:BFS+hash判重模拟过程。1、通过STL重载来实现hashstruct cmp{ bool operator () (int a, int b) const { return memcpy(a.map, b.map, 25) < 0;}};2、hash判重,注意状态转移。CODE:#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<qu 阅读全文
posted @ 2012-10-11 21:44 有间博客 阅读(409) 评论(0) 推荐(0) 编辑
摘要: CODE:#include<cstdio>#include<cstdlib>#include<iostream>#include<cstring>usingnamespacestd;#defineMAXN30#defineINF0X3F3F3F3FintG[MAXN][MAXN];boolvis[MAXN][MAXN];intans,n,m;voidinit(){memset(G,0,sizeof(G));ans=-INF;}voiddfs(intu,intcur){if(cur>ans)ans=cur;for(intv=0;v<n; 阅读全文
posted @ 2012-10-11 16:49 有间博客 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 大意:排序,求数字第一次出现的位置。CODE:#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>usingnamespacestd;intn,m;inta[10001];intcmp(constvoid*a,constvoid*b){return*(int*)a-*(int*)b;}intmain(){inttimes=0;while(~scanf("%d%d",&n,&m)&&(n||m)){for(inti 阅读全文
posted @ 2012-10-11 15:57 有间博客 阅读(138) 评论(0) 推荐(0) 编辑
摘要: CODE:#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<set>usingnamespacestd;set<int>vis;voidinit(){vis.clear();}intgetNumber(intn){ints=0;while(n){s+=(n%10)*(n%10);n/=10;}returns;}intmain(){inttimes=0;intT,ans,n;scanf("%d",&am 阅读全文
posted @ 2012-10-11 13:34 有间博客 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 简单回溯CODE:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>usingnamespacestd;constintSIZE=6;intMAX;intmaze[SIZE][SIZE];intN;intcheck(intr,intc){inti;for(i=r-1;i>=0;i--){if(maze[i][c]=='Y')return0;if(maze[i][c]=='X')bre 阅读全文
posted @ 2012-10-11 13:16 有间博客 阅读(156) 评论(0) 推荐(0) 编辑
  2012年10月10日
摘要: 大意:隐式图的遍历。思路:通过BFS模拟倒水的过程。1、当前容器不为空且被倒容器还有剩余的体积。2、通过3维数组来判重。3、由于求的是最小的倒水量,如果最小量不存在则求最接近于要求倒水量的d,于是我们可以通过从大到小枚举每一个d值来求。CODE:#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<queue>usingnamespacestd;#defineMAXN210constintINF=0x3f3f3f3f;structnod 阅读全文
posted @ 2012-10-10 20:11 有间博客 阅读(547) 评论(0) 推荐(0) 编辑
  2012年10月9日
摘要: CODE:#include<cstdio>#include<cstring>#include<iostream>usingnamespacestd;#defineMAXN8intG[MAXN][MAXN];intA[MAXN];boolvis[3][MAXN*2];intans;voiddfs(intn,intcur=0){if(cur==n){inttot=0;for(inti=0;i<n;i++)tot+=G[i][A[i]];if(tot>ans)ans=tot;}elsefor(inti=0;i<8;i++){A[cur]=i;if 阅读全文
posted @ 2012-10-09 21:10 有间博客 阅读(130) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 30 下一页