摘要: 传送门:Ubiquitous Religions 许多次WA,贴上错的代码随时警示 简单没多加修饰的并查集 【WA1】 #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int 阅读全文
posted @ 2017-08-10 10:04 GGBeng 阅读(175) 评论(0) 推荐(0) 编辑
摘要: set函数的应用 超级水题 set函数的应用 超级水题 阅读全文
posted @ 2017-08-10 01:00 GGBeng 阅读(294) 评论(0) 推荐(0) 编辑
摘要: 分析:栈的应用,遇到右括号便弹出栈顶元素,看是否与右括号相互匹配,其余情况压入栈。 注意:本题有坑,空串空串,为此我跪了数次 阅读全文
posted @ 2017-08-10 00:27 GGBeng 阅读(282) 评论(0) 推荐(0) 编辑
摘要: 水题 练习一下堆栈和队列的使用 阅读全文
posted @ 2017-08-09 22:39 GGBeng 阅读(460) 评论(0) 推荐(0) 编辑
摘要: 一、深入理解DFS 采用递归写法 深度优先,思路就是沿着一条路一直走,直到走到死胡同,原路返回,返回到有多条道路的地方换其他路走。直到这条支路全部都访问过了,按照原路返回,回到起点,如果起点还有别的支路,那么继续访问,反之结束整个搜索过程。 实际解题的时候不可能无所约束的搜索下去,原因之一是会超时( 阅读全文
posted @ 2017-08-09 19:13 GGBeng 阅读(461) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:zxa and leaf Sample Input 2 3 2 1 2 1 3 2 4 3 9 6 2 1 2 1 3 1 4 2 5 2 6 3 6 5 9 Sample Output 3 1 Hint If you need a larger stack size, pl 阅读全文
posted @ 2017-08-09 01:27 GGBeng 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:Alyona and a tree Examples Input 52 5 1 4 61 71 13 53 6 Output 1 0 1 0 0 Input 59 7 8 6 51 12 13 14 1 Output 4 3 2 1 0 Note In the example 阅读全文
posted @ 2017-08-09 01:20 GGBeng 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:Prime Ring Problem Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circl 阅读全文
posted @ 2017-08-09 01:12 GGBeng 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:Anti-prime Sequences Sample Input 1 10 2 1 10 3 1 10 5 40 60 7 0 0 0 Sample Output 1,3,5,4,2,6,9,7,8,10 1,3,5,4,6,2,10,8,7,9 No anti-prime 阅读全文
posted @ 2017-08-09 01:01 GGBeng 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:Sticks 题意:给出一定数量的小木棒的长度,它是由等长的若干木棒随意砍断所得到的。对于给定的一组小木棒,请求出原始木棒的最小长度。 二、解题思路 DFS+剪枝 本题剪枝不到一定火候将会TLE,只有完成一定的剪枝才能AC 本题,我将从我做这题的角度,将所思所想具体记录下来, 阅读全文
posted @ 2017-08-08 16:52 GGBeng 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:Oil Deposits 题意:给你一块网格,网格被分为面积相等的地块,这些地块中标记'@'的是油田,标记'*'的不是油田。已知一块油田与它上下左右以及对角线的油田同属一片油区,请问总共有多少油区。 二、解题思路 DFS经典 注意的就是要向八个方向搜索,搜索完一处,将该处变成 阅读全文
posted @ 2017-08-08 14:04 GGBeng 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:Lotto Sample Input 7 1 2 3 4 5 6 7 8 1 2 3 5 8 13 21 34 0 Sample Output 1 2 3 4 5 6 1 2 3 4 5 7 1 2 3 4 6 7 1 2 3 5 6 7 1 2 4 5 6 7 1 3 4 阅读全文
posted @ 2017-08-08 13:04 GGBeng 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 1 long long quickmod(long long a,long long b,long long m) 2 { 3 long long ans = 1; 4 while(b)//用一个循环从右到左便利b的所有二进制位 5 { 6 if(b&1)//判断此时b[i]的二进制位是否为1 7 { 8 ... 阅读全文
posted @ 2017-08-08 10:57 GGBeng 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 1 # include 2 # include 3 # include 4 # define max(x,y) x>y?x:y; 5 int v[1001];//价值 6 int w[1001];//重量 7 int dp[1001][1001]; 8 int main() 9 { 10 int n,m; 11 while(scanf("%d%d",&m,... 阅读全文
posted @ 2017-08-08 10:56 GGBeng 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 1 int gcd(int n,int m)//n>m 2 { 3 //最大公约数 4 int r; 5 while(m) 6 { 7 r = n%m; 8 n = m; 9 m = r; 10 } 11 return n; 12 } 13 14 int kgcd(int a,in... 阅读全文
posted @ 2017-08-08 10:54 GGBeng 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 struct point 8 { 9 double x,y; 10 }; 11 point a[105][2];//a[i][0]代表第i条线段的头,a[i][1]代表尾 12 13 double fan(double... 阅读全文
posted @ 2017-08-08 10:53 GGBeng 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 1 //sort 2 #include 3 bool cmp(const int a,const int b) 4 { 5 return a>b;//降序排列 6 } 7 8 //qsort 9 #include 10 int cmp(const void *x,const void *y) 11 { 12 return (*(int*)x-*(int*)y... 阅读全文
posted @ 2017-08-08 10:52 GGBeng 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 1 int binsearch(int *t,int k,int n) 2 {//t为数组,k是要查找的数,n为长度,此为升序 3 int low = 1,high = n,mid; 4 while(low<=high) 5 { 6 mid = (low+high)/2; 7 if(k == t[mid]) 8 ... 阅读全文
posted @ 2017-08-08 10:49 GGBeng 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 3 int main() 4 { 5 int i,j,a[505]={0}; 6 for(i=1;i<=500;i++) 7 a[i]=1; 8 for(i=2;i<=500;i++) 9 if(a[i]) 10 for(j=i+i;j<=500;j+=i) 11 ... 阅读全文
posted @ 2017-08-08 10:48 GGBeng 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 1 int next[N]; 2 char str1[M],str2[N]; 3 //str1 长,str2 短 4 //len1,len2,对应str1,str2的长 5 6 void get_next(int len2) 7 { 8 int i = 0,j = -1; 9 next[0] = -1; 10 while(ilen2... 阅读全文
posted @ 2017-08-08 10:48 GGBeng 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 1 int find(int x) 2 { 3 int r = x; 4 while(father[r]!=r) 5 r = father[r]; 6 return r; 7 } 8 /* 9 int find(int x) 10 { 11 if(father[x] == x) 12 return x; 13 else 1... 阅读全文
posted @ 2017-08-08 10:46 GGBeng 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 struct node 7 { 8 int x,y,step; 9 }; 10 11 char map[105][105]; 12 int vis[105][105]; 13 int to[4][2]= {1,0,-1,0,0,1,0,-1}... 阅读全文
posted @ 2017-08-08 10:45 GGBeng 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:棋盘问题 Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。 Description 在一个给定形状的 阅读全文
posted @ 2017-08-08 10:00 GGBeng 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个 阅读全文
posted @ 2017-08-08 00:17 GGBeng 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 一、题目回顾 题目链接:Tempter of the Bone Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it 阅读全文
posted @ 2017-08-07 22:31 GGBeng 阅读(162) 评论(0) 推荐(0) 编辑