上一页 1 ··· 4 5 6 7 8 9 下一页
  2011年8月25日
摘要: 我用的是dij最短路做。刚开始wa了。因为记录路径的问题。。。太菜了。#include<iostream>using namespace std;int n,m;const int N=1005;bool mat[N][N];bool visit[N];int d[N];int pre[N];const int inf=9999999;void print(int u){if(u==1)printf("%d\n",u);else{print(pre[u]);printf("%d\n",u);}}void dij(){for(int i=1;i 阅读全文
posted @ 2011-08-25 14:26 不是我干的 阅读(266) 评论(0) 推荐(0)
  2011年7月26日
摘要: 这是道烂题目,思路的难度比阅读题目的难度还低。然后输出的恶心格式。反正就是烂题。#include<iostream>#include<string>#include<vector>using namespace std;const int N=22;int street[N][N];unsigned int dist[N];int n;bool visit[N];int pre[N];int des;int org[N];string out[N];int time[N];vector<int> vec[N];void print(int who 阅读全文
posted @ 2011-07-26 20:41 不是我干的 阅读(173) 评论(0) 推荐(0)
  2011年7月25日
摘要: 思路简单,BFS,就是其中一些小技巧比较恶心。代码也写得恶心。#include<iostream>//#include<queue>#include<string>using namespace std;const int N=105;char str[7][10]={"","FILL(1)","FILL(2)","DROP(1)","DROP(2)","POUR(1,2)","POUR(2,1)"};int visit 阅读全文
posted @ 2011-07-25 01:38 不是我干的 阅读(139) 评论(0) 推荐(0)
  2011年7月24日
摘要: 还能比这道题更水吗。只要看的懂题意直接模拟法写了就行。没编译器的话甚至直接在记事本上写写交了也可以AC的。#include<iostream>using namespace std;const int N=205;char s1[N],s2[N],s12[N],s01[N],s02[N];int c;int ans;bool same(char a[],char b[],int c){ for(int i=1;i<=c;i++) { if(a[i]!=b[i]) return false; } return true;}void f(){ char s[N]; for(int 阅读全文
posted @ 2011-07-24 01:58 不是我干的 阅读(187) 评论(0) 推荐(0)
  2011年7月21日
摘要: 这题。。。。一次就A了。有点太水了。其中本来还觉得就判断质数比较耗时。其实只要先制成一张质数的表。每次去查就行了。耗时就小了。#include<iostream>#include<math.h>#include<queue>using namespace std;int data,target;bool prime[10005];int visit[10005];bool isprime(int t){ for(int i=2;i<=sqrt(double(t));i++) if(t%i==0) return false; return true; } 阅读全文
posted @ 2011-07-21 23:23 不是我干的 阅读(173) 评论(0) 推荐(0)
  2011年7月19日
摘要: BFS水过去,但是还得用到__int 否则就纠结了。#include<iostream>using namespace std;const int N=200,M=100;int n;__int64 que[9999999];void bfs(){ int head=1,tail=1; que[tail++]=1; while(head<tail) { __int64 now=que[head++]; if(now%n==0) { printf("%I64d\n",now); return; } que[tail++]=now*10; que[tail++ 阅读全文
posted @ 2011-07-19 22:01 不是我干的 阅读(130) 评论(0) 推荐(0)
摘要: 只要能看懂题就知道bfs一下就出来了。唯一思考了一下的地方是记录步数。我用的int visit[N]来记录步数。我觉得效果还行。#include<iostream>#include<queue>using namespace std;const int N=200005;const int K=200005;int visit[N];int n,k,ans;void bfs(){ queue<int> que; que.push(n); visit[n]=1; while(!que.empty()) { int now=que.front(); que.po 阅读全文
posted @ 2011-07-19 20:05 不是我干的 阅读(155) 评论(0) 推荐(0)
  2011年7月17日
摘要: 很简单。失误的是刚开始用DFS,超时了。#include<iostream>#include<queue>using namespace std;const int N=35;struct node{ int l,r,c,step; node(int a1=0,int a2=0,int a3=0,int ste=0) {l=a1;r=a2;c=a3;step=ste;}};int mov[6][3]={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};char maze[N][N][N];bool visit[N][ 阅读全文
posted @ 2011-07-17 23:49 不是我干的 阅读(158) 评论(0) 推荐(0)
摘要: 这题让我真正理解了回溯,之前自己写的代码一直写不好,对回溯理解不好。dfs(y+1,step);这个代码一下子就解决了回溯的问题。还是太菜了。还有一点就是,之前的DFS都是上下左右的移动,这次刚开始做不好就是没理解透。其实这次的以行为节点,然后以列为上下左右去移动。这样写出来的代码才会精炼合理。#include<iostream>using namespace std;const int N=10;int maze[N][N];int n,k;int ans;bool visit[N];void dfs(int y,int step){ if(step==k) { ans++; r 阅读全文
posted @ 2011-07-17 22:01 不是我干的 阅读(190) 评论(0) 推荐(0)
摘要: DFS的简单应用。#include<iostream>using namespace std;const int N=25;int movex[4]={0,0,-1,1};int movey[4]={-1,1,0,0};int maze[N][N]; int nx,ny;struct node{ int x,y; node(int _x=0,int _y=0){x=_x;y=_y;}};node start;node getnext(node now,int dire){ int x=now.x; int y=now.y; if(maze[y+movey[dire]][x+move 阅读全文
posted @ 2011-07-17 08:56 不是我干的 阅读(162) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 下一页