上一页 1 ··· 7 8 9 10 11
摘要: BFS 判断可达性 邻接vector存储 1 # include 2 # include 3 # include 4 # include 5 # include 6 # define N 1010 7 using namespace std; 8 9 bool vis[N];10 vectorG[N];11 12 void add(int u, int v)13 {14 G[u].push_back(v);15 }16 17 bool BFS(int s)18 {19 queueq;20 q.push(s);21 vis[s] = true;22 ... 阅读全文
posted @ 2013-08-09 13:25 GLSilence 阅读(306) 评论(0) 推荐(0) 编辑
摘要: 基于邻接矩阵的BFS: 1 # include 2 # include 3 # include 4 # include 5 # include 6 # define N 1010 7 using namespace std; 8 9 int map[N][N];10 int vis[N], p[N];11 queueq;12 int t = 0, n;13 14 void BFS(int s)15 {16 vis[s] = 1;17 for(int i = 0; i > o;38 while(o--)39 {40... 阅读全文
posted @ 2013-08-09 11:03 GLSilence 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 数据量很大时 long long中间也会溢出 所以要拆分开来做 1 # include 2 # include 3 # define LL long long 4 5 LL i, len, n, m; 6 LL a[110]; 7 8 void f(int n) 9 {10 for(i = 0; i = 0; i--)18 {19 if(a[i] != 0)20 break;21 }22 len = i+1;23 }24 25 int main(void)26 {27 ... 阅读全文
posted @ 2013-08-08 20:46 GLSilence 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 题目大意:有一个4*4的方格,每个方格中放一粒棋子,这个棋子一面是白色,一面是黑色。游戏规则为每次任选16颗中的一颗,把选中的这颗以及它四周的棋子一并反过来,当所有的棋子都是同一个颜色朝上时,游戏就完成了。现在给定一个初始状态,要求输出能够完成游戏所需翻转的最小次数,如果初始状态已经达到要求输出0。如果不可能完成游戏,输出Impossible。主要思想:1.如果用一个4*4的数组存储每一种状态,不但存储空间很大,而且在穷举状态时也不方便记录。因为每一颗棋子都只有两种状态,所以可以用二进制0和1表示每一个棋子的状态,则棋盘的状态就可以用一个16位的整数唯一标识。而翻转的操作也可以通过通过位操作来 阅读全文
posted @ 2013-08-03 09:26 GLSilence 阅读(723) 评论(0) 推荐(0) 编辑
摘要: # include # include struct node{ int data; struct node *next;} ;struct node *creat1(int n) //顺序建立链表{ struct node *head, *tail, *p; head = (struct node *)malloc(sizeof(struct node )); head -> next = NULL; tail = head; for(int i = 0; i data); p -> next = NULL; tail... 阅读全文
posted @ 2013-06-17 11:23 GLSilence 阅读(285) 评论(0) 推荐(0) 编辑
摘要: /************************************** Problem id : SDUT OJ 2178 User name : Silence-Debug Result : Accepted Take Memory : 316K Take Time : 0MS Submit Time : 2013-05-31 21:05:15 **************************************/ # include # include ... 阅读全文
posted @ 2013-05-31 21:11 GLSilence 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 1 # include 2 # include 3 # define N 10000 4 5 char s1[N], s2[N]; 6 int a[N]; 7 8 int main(void) 9 {10 while(~scanf("%s%*c%s", s1, s2))11 {12 int n = strlen(s1)-1;13 int m = strlen(s2)-1;14 int t = 0;15 int qian = 0;16 while(n >= 0 && m >= 0)17 ... 阅读全文
posted @ 2013-05-22 19:31 GLSilence 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 本来是在链表里的比赛,可是我没用链表,主要是链表不会排序......最后输出奖项的时候卡了好长时间,最后还是问的芳姐 · - ·本来是150ms的,去掉几个没用的排序之后,成10ms了,还是跑秒了=_=!/**************************************Problem id: SDUT OJ J User name:Silence—DebugResult: Accepted Take Memory: 1328K Take Time: 10MS Submit Time: 2013-03-20 20:28:08 ******************* 阅读全文
posted @ 2013-03-20 20:34 GLSilence 阅读(305) 评论(0) 推荐(0) 编辑
摘要: 1 # include 2 # include 3 4 struct node 5 { 6 int date; 7 struct node *next; 8 } ; 9 10 struct node *creat(int n)11 {12 struct node *head, *tail, *p;13 head = (struct node *)malloc(sizeof(struct node));14 head -> next = NULL;15 tail = head;16 for(int i = 0; i date);2... 阅读全文
posted @ 2013-03-16 12:59 GLSilence 阅读(253) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11