Shirlies
宁静专注认真的程序媛~
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 21 下一页
摘要: 不知道怎么下手,真没有想到这一题就来拓扑排序,本来看到这一题是觉得要用拓扑的,可是这一题是属于并查集的,并且也不知道怎么用拓扑来处理,汗,搜搜,发现竟然还可以用队列来实现拓扑,精神!是参考以下代码的:http://972169909-qq-com.iteye.com/blog/1052820 阅读全文
posted @ 2012-03-05 22:12 Shirlies 阅读(591) 评论(0) 推荐(0) 编辑
摘要: 这一题是听同学讲过例题后,现在做起来,感觉特别有意思。rank表示当前点到父节点的距离,如果距离是奇数,那么这两个就是异性,否则是同性,所以可以用%2判定他们之间的性别。以下注释是根据自己的理解写的,其实也不太清楚自己的理解是否是正确的^_^View Code 1 #include "stdio.h" 2 #include "string.h" 3 4 int f[3000]; 5 int rank[3000]; 6 7 int find(int x) 8 { 9 int t;10 if(x==f[x])11 return x;12 13 t=fi... 阅读全文
posted @ 2012-03-05 11:13 Shirlies 阅读(1019) 评论(2) 推荐(1) 编辑
摘要: 题意:就是用一个球a去撞另外一个球b(如果两个相邻是撞不了的),球a停在球b前,球b被撞出去了,少了一个球咯,如果一行有多个球,那么就一个传一个咯,题目要求的结果是最后只剩下一个球。每次都得从头开始搜,我认为是不能只用结构体存储'O'的位置的,必须得用数组存储,因为,每次撞球后位置改变了,结构体存储的点的顺序是会变化的,而下一次搜索又是必须得按顺序开始搜的(即从左上角开始),如果对变化后的结构体排序的话,那么回溯回来又怎么办?反正我是想不到办法了,然后改成数组存储了。我写的挺复杂的,其实思路挺简单的。View Code 1 #include <iostream> 2 阅读全文
posted @ 2012-03-04 23:09 Shirlies 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 数独,O(∩_∩)O哈哈~做了这道,以后什么数独就可以直接得出答案了……View Code 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 5 int sudo[9][9]; 6 int flag; 7 8 void dfs(int a,int b); 9 int is_repeat(int i,int j,int k); 10 11 int main() 12 { 13 char a; 14 int cas=0; 15 while(cin>>a) 16 ... 阅读全文
posted @ 2012-03-02 19:22 Shirlies 阅读(452) 评论(0) 推荐(0) 编辑
摘要: 这是一道纯粹的拓扑排序,刘汝佳的《算法入门经典》p110里面有例题. 1 #include "stdio.h" 2 #include "string.h" 3 4 int task[102][102]; 5 int vis[102]; 6 int n,m; 7 int k; 8 int topo[102]; 9 10 int dfs(int u);11 void toposort(void);12 13 int main()14 {15 int i;16 int a,b;17 while(scanf("%d%d",&n,&am 阅读全文
posted @ 2012-03-01 22:38 Shirlies 阅读(890) 评论(0) 推荐(0) 编辑
摘要: 这一题是参考别人的,但是此题用到了映射,第一次用映射,感觉到了stl的方便之处http://blog.csdn.net/acb0y/article/details/5865561 阅读全文
posted @ 2012-03-01 22:33 Shirlies 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 这一题死的很悲剧,就n值问题,起初我还一直以为是排序的cmp出问题了,检查它,却忽略了后面的检查……呜呜~~~~(>_<)~~~~ 竟然wa了那么多次,而且用了那么长时间,如此基础的题目,看来我检查错误的能力还有待改善啊~~~View Code #include <cstdio>#include <cstdlib>#include <string>using namespace std;struct node{ char a1[100]; char b1[100]; char c1[100];}in[1000];int cmp(const voi 阅读全文
posted @ 2012-02-28 23:21 Shirlies 阅读(193) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <cstdio>#include <cstring>using namespace std;char maze[31][81];char s[81];int xx,yy;int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};void dfs(int x,int y);int main(){int T;char ch;char a[82];int k=0;scanf("%d",&T);getchar();while(T--){int i=0,j;x 阅读全文
posted @ 2012-02-23 21:05 Shirlies 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 起初没有看懂题目,无处下手,就去翻翻别人的代码,才知道题目的意思,汗……简单的一般的广搜的变形,这个解释的比较详细http://blog.csdn.net/swm8023/article/details/6765219虽然知道怎么做了,但是还是犯错误,最后与上面这份代码比较之后才找出错误#include <iostream>#include <cstring>#include <queue>using namespace std;char map[102][102];int vis[102][102];int n,m,time,ans;int fx[21], 阅读全文
posted @ 2012-02-22 22:35 Shirlies 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 虽然多了一层,但是还是比较基础的搜索题目,在T时间内,其实只要求出最小时间就可以了,然后比较两者,既然是求最小的时间,那么用广搜就比较好了……#include <iostream>#include <cstring>#include <queue>using namespace std;struct node{int f;int x,y;}n1;char map[2][12][12];int vis[2][12][12];int n,p,t,time;int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};int fp,xp,yp 阅读全文
posted @ 2012-02-21 19:13 Shirlies 阅读(456) 评论(0) 推荐(0) 编辑
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 21 下一页