摘要: #include #include #include using namespace std;int A,B,C,vis[101][101];char str[6][10] = {"FILL(1)", "FILL(2)", "DROP(1)", "DROP(2)", "POUR(1,2)", "POUR(2,1)"};structnode{ int num,a,b; node *pre;};node que[101*101];void print(node now){ if 阅读全文
posted @ 2013-12-09 19:16 单调的幸福 阅读(180) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std; //min()使用的时候要特别注意int maze[25][25],dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}},ans,R,C;void DFS(int x,int y,int step){ if (step>10) return ; for (int i=0;i=0 && a=0 && b1) //紧挨着石头(flag=1)时,不能动; { maze[a][b]=0; DF... 阅读全文
posted @ 2013-12-08 16:15 单调的幸福 阅读(174) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #include #include using namespace std;structloc{ int row,col,lev,time;};char maze[40][40][40];int dir[6][3]={{0,1,0},{0,-1,0},{1,0,0},{-1,0,0},{0,0,1},{0,0,-1}},vis[40][40][40];loc sta,end;int main(){ int L,R,C,i,j,k,fine,R0,C0,L0,Re,Ce,Le,R1,C1,L1,time; while(sca... 阅读全文
posted @ 2013-11-25 16:59 单调的幸福 阅读(158) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #include #define maxs 100005using namespace std;int b[maxs],visit[maxs];void prtable(){ int i,j; for (i=1000;i Q; memset(visit,0,sizeof(visit)); Q.push (a); visit[a]=1; while (!Q.empty() && !fine) { tt=Q.size();//队列里元素的个数... 阅读全文
posted @ 2013-11-24 17:34 单调的幸福 阅读(230) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std;int vis[100005]={0},n,k,t;int main(){ queue Q; scanf("%d%d",&n,&k); Q.push(n); while(!Q.empty()) { t=Q.front(); Q.pop(); if (t==k) break; //第一个达k的肯定是最快的,直接跳出循环输出即可 if (t>0 && !vis[t-1]) //三种... 阅读全文
posted @ 2013-11-19 22:08 单调的幸福 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 跟n皇后问题一样,DFS和回溯经常搭配到一起,这里用到了简单的回溯#include #include int col [10],n,k,num;char maze[10][10];void DFS(int x,int k){ int i,j; if(k==0) {num++;return ;} //走得通,结束加1 for (i=x;i<n;i++) for (j=0;j<n;j++) { if ( !col[j] && maze[i][j]=='#') { ... 阅读全文
posted @ 2013-11-19 20:32 单调的幸福 阅读(186) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std; //用queue一定要用std;int dir1[4][2]={{0,1},{1,0},{0,-1},{-1,0}},vis[50][50];//右,下,左,上;int dir2[4][2]={{0,1},{-1,0},{0,-1},{1,0}},r0,c0,rn,cn,row,col;char maze[50][100];structpath{ int rr,cc,step;};int DFS (int r0,int c0,int to,int dir[][2]){ if (r0=... 阅读全文
posted @ 2013-11-18 19:14 单调的幸福 阅读(143) 评论(0) 推荐(0) 编辑
摘要: #include #include structpos{ int x,y;};pos path[50];int p,q,visit[50][50],step,a[8][2]={{-2,1},{-2,-1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}}; //一定要保证是字典顺序int DFS (int r,int c){ path[step].x=r; path[step++].y=c; if (step>p*q) return 1; int R,C; for (int i=0;i0 && C0 && ... 阅读全文
posted @ 2013-11-17 15:41 单调的幸福 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 在poj上C++可以AC,但G++不行。杭电上更是好多的TLE,结果把cin改成scanf便可以轻松AC。#include #include #include #include #include using namespace std;#define N 1010structx_y{ double x,y;};bool greater_(x_y ex1,x_y ex2){ return ex1.xd1) flag=1; } if(flag) { printf("Case %d: %d\n",k,-1); ... 阅读全文
posted @ 2013-11-16 12:38 单调的幸福 阅读(166) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #define N 10005#define M 100100int dp[3][M],a[N];using namespace std;int max (int a,int b){ return a>b?a:b;}int main(){ int m,n,i,k,k1,j,L=0,nk,dk; while (cin>>m>>n) { memset (dp,0,sizeof(dp)); memset (a,0,sizeof(a)); k=0; while (n--... 阅读全文
posted @ 2013-11-15 21:10 单调的幸福 阅读(253) 评论(0) 推荐(0) 编辑