摘要:
Number SequenceTime Limit: 10000/5000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9899Accepted Submission(s): 4518Pr... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(84)
评论(0)
推荐(0)
摘要:
C. Magic Formulastime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPeople in the Tomskaya region l... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(143)
评论(0)
推荐(0)
摘要:
水题:直接模拟即可,次数cnt = abs(cnt1-cnt2)/2;#include#include#include#include#includeusing namespace std;int main(){ string s; int n, ans; while(~scanf... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(133)
评论(0)
推荐(0)
摘要:
对于每头牛可以取或者不取,因此两种方法:dfs或二进制枚举,不过二进制枚举比较慢,但一般来说都能在题目限定时间内出解。1.DFS(32ms):#include#include#include#include#include#define INF 0x7fffffffusing namespace s... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(90)
评论(0)
推荐(0)
摘要:
题意:平面上给你n个点。1为起始点,问你从1号点出发经过其他所有点再回到1号点的最短距离,两点之间的距离是曼哈顿距离(abs(x1-x2)+abs(y1-y2))。思路:DFS,算出每次的距离,取最短即可。#include#include#include#include#include#define... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(124)
评论(0)
推荐(0)
摘要:
使用C/C++处理大数据时有时不是很方便,这时可以使用JAVA中大数类,当然代价就是运行时慢。import java.math.*;import java.util.*;import java.io.*;import java.text.*;public class test{ public ... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(206)
评论(0)
推荐(0)
摘要:
题意:给你一串数字,问你他们能组成多少个不同的素数。思路:枚举这些数字的组合的排列,打一张素数表直接判断。这题时间限制很紧啊(1000ms),在无限TLE之后,我把memset(vis,0,sizeof(vis))这句删除之后跑了844ms,险过,memset怎么会那么坑,不是说内部实现是调用批处理... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(112)
评论(0)
推荐(0)
摘要:
思路:1.最基本的,需要用到矩阵快速幂 2.快速幂求完之后怎样快速求和?若逐项累加求和必然会超时,这时需要求递推公式:(1)若n为偶数,则:S(n) = A^(n/2)*S(n/2)+s(n/2);(2)若n为奇数 S(n) = A^(n/2+1) + S(n/2)*A^(n/2+1) + S(n/... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(99)
评论(0)
推荐(0)
摘要:
思路:矩阵快速幂,没什么可说的。#include#include#include#include#includeusing namespace std;typedef struct Matrix{ int m[2][2]; Matrix(){ memset(m, 0, si... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(141)
评论(0)
推荐(0)
摘要:
题意:在无向图中有n条边,现在给出你一个起点S和一个终点E,让你求从S到E经过且仅K条边的最短路径。注意此题中K远大于n,如果K小于n的话直接一边广搜就过了,第一次没注意到这个条件敲了一个BFS,结果WA了。思路:此题正解应该是矩阵乘法,但是重定义了,区别于线性代数里面的乘法(其实可以看出无论哪种定... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(193)
评论(0)
推荐(0)
摘要:
思路:dfs,试填每个方格,当搜索的范围超过9×9时说明已经找到解#include#include#include#include#includeusing namespace std; int map[15][15], flag; bool CanPlace(int x, int y, int n... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(118)
评论(0)
推荐(0)
摘要:
思路:二进制枚举,再用位运算来判断选的那些行是否满足每列只有一个1,(很神奇的位运算)。考虑最多16行,因此可以用一个int型(32位>16)的每个二进制位来表示每列状态,比如某列的第二行有个1,则int型数字里面第二个二进制位就为1,时间复杂度2^16*m,可以接受。这里存在一个问题就是怎么通过每... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(336)
评论(0)
推荐(0)
摘要:
利用深度优先搜索的性质可以方便的生成n的排列和组合。生成排列(默认是全排列,也可以传个参数生成n的k排列)#include#define MAXN 111using namespace std;int tmp[MAXN],vis[MAXN],n,k;void dfs(int cnt,int num ... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(170)
评论(0)
推荐(0)
摘要:
1.DFS:#include#include#include#include#include#include#includeusing namespace std; char str[20], ans[10]; int vis[20], flag; bool cmp(char a, char b){... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(144)
评论(0)
推荐(0)
摘要:
#include#include#include#include#include#define MAXN 20010using namespace std;typedef struct{ int to,next;}Node;typedef struct PP{ int id,par; ... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(90)
评论(0)
推荐(0)
摘要:
#include#include#include#include#include#define MAXN 1111using namespace std;class Point{ public: int x,y; bool operator > 1; ... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(126)
评论(0)
推荐(0)
摘要:
1 #include 2 #include 3 #include 4 #include 5 #include 6 #define MAXN 50010 7 using namespace std; 8 typedef struct PP{ 9 int id,par;10 bool ... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(133)
评论(0)
推荐(0)
摘要:
#include #include #include #include #define MAXN 1000010 #define LL long long const LL INF = 0x7fffffffffffff; using namespace st... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(96)
评论(0)
推荐(0)
摘要:
思路:需要用到位运算,D最为16,用一个int数(32位 > 16位,足够表示)的每个二进制位表示病毒的存在与否,1为存在,0不存在,这样复杂度为2^16*n(通过剪枝实际达不到这么大),可以接受。因此有两种方法解本题,(1),dfs,枚举D的k-组合。(2),通过二进制枚举D的k-组合。用dfs,... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(207)
评论(0)
推荐(0)
摘要:
思路:Trie树,很早以前写过,但代码写的太屎,今天做别人比赛遇到了,就重写了一次。#include#include#include#include#include#includeusing namespace std;class Node{ public: int cnt; ... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(82)
评论(0)
推荐(0)
摘要:
思路:年前学得Trie树,当时没过,可能当时没完全理解吧,今天碰到了,就凭着理解直接敲的,调了两次终于过了,把每个单词结尾标记为1,查询的时候看某个单词的子串是否存在,这题WA点不少,必须搞清判断条件。#include#include#include#include#includeusing nam... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(106)
评论(0)
推荐(0)
摘要:
思路:动态规划,设dp[i][j]表示从i到j这段子串匹配的最大长度,则状态转移方程分两种情况,1.若从i到j-1这些字符中没有一个能与j匹配,则 dp[i][j] = dp[i][j-1],这是显然的;2.若从i到j-1中有字符能与j匹配(可能不止一个,并设他们组成集合为A),则 dp[i][j]... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(105)
评论(0)
推荐(0)
摘要:
思路:动态规划,不论怎么取则必须有一个最后取(设为k),设dp[n][m] 是n到m这段中的最优解,则dp[n][m] = min(dp[n][k]+dp[k][m]+a[k]*a[n]*a[m],dp[n][m])(k > n && k #include#include#include#defin... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(105)
评论(0)
推荐(0)
摘要:
Til the Cows Come HomeTime Limit:1000MSMemory Limit:65536KTotal Submissions:27591Accepted:9303DescriptionBessie is out in the field and wants to get b... 阅读全文
posted @ 2014-04-30 18:39
wangzhili
阅读(144)
评论(0)
推荐(0)
摘要:
#include#include#include#include#include#include#define MAXN 105using namespace std; typedef struct{ int num[10], a, b; char str[10]; void S... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(96)
评论(0)
推荐(0)
摘要:
#include#include#include#include#include#include#define MAXN 20using namespace std; int a[MAXN], temp[MAXN], vis[MAXN]; int T, N, flag, sum; string ss... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(119)
评论(0)
推荐(0)
摘要:
#include#include#include#define MAXN 10 using namespace std; int s[MAXN], p[MAXN]; string in, out; int main(){ int n, flag, k, i, j, top; while... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(90)
评论(0)
推荐(0)
摘要:
#include#include#includeusing namespace std;int main(){ int n,k; while(~scanf("%d%d",&n,&k)){ if(n == 1 && k > 0 || k < n / 2) printf("-... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(61)
评论(0)
推荐(0)
摘要:
思路:动态规划,设dp[i][j]表示第i个字符到第j个字符所需要的最少匹配数,则:(1),如果从第i到j-1个字符中没有一个与第j个字符匹配,那么状态转移方程为 dp[i][j] = dp[i][j-1] + 1 (2),如果在第i到j-1字符中存在与第j个字符匹配的字符(记为k,且把所有满足条件... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(98)
评论(0)
推荐(0)
摘要:
思路:利用Karp-Rabin算法的思想,对每个子串进行Hash,如果Hash值相等则认为这两个子串是相同的(事实上还需要做进一步检查),Karp-Rabin算法的Hash函数有多种形式,但思想都是把字符串映射成一个数字。本题hash函数是把字串转化为NC进制的数(实际上程序中计算结果已经被转换为1... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(132)
评论(0)
推荐(0)
摘要:
思路:很坑爹的一道水题么,题目没说字符串有多长,一开始开的长度是30,一直RE。另外如果没有重复的输出的是No duplicates.,注意有句点。。。两种解法:map或者二叉搜索树中序遍历一次,维护一个cnt(记录次数)域。#include#include#include#include#incl... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(89)
评论(0)
推荐(0)
摘要:
这个链接里面对map的讲解比较好。http://blog.csdn.net/iicy266/article/details/11906189 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(80)
评论(0)
推荐(0)
摘要:
思路:先选定1为树根,进行第一次深搜,很容易求出节点u到其子节点的最长距离和次长距离,求次长距离的目的是如果u的跟节点最长路径经过u则dp的时候就不能取其跟节点的最长距离,应该取其次长距离;然后进行第二次深搜,搜索节点u经过其跟节点的最长距离。如果令dp[u][0],dp[u][1],分别为节点u到... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(90)
评论(0)
推荐(0)
摘要:
1.堆排序是一种优秀的排序算法,时间复杂度O(nlogn),主要思想是用数组构造一个最大堆,满足跟节点的value>子节点的value,然后将堆顶元素(value最大)与最后一个叶子节点交换,再调整堆,使其满足最大堆的性质,重复上述步骤n-1次后就得到一个有序序列。#include#include#... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(302)
评论(0)
推荐(0)
摘要:
思路:dp[i]表示所求答案,则dp[pos[str[i]-'a']] = min(dp[pos[str[i]-'a']], i - pos[str[i]-'a']) ; dp[i] = i - pos[str[i]-'a'];pos 记录与当前字母相同的且离当前位置最近的字母的位置。/*USER_... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(340)
评论(0)
推荐(0)
摘要:
思路:深度优先搜索,一层一层由子节点向跟节点回溯。1.#include#include#include#include#define MAX 11111using namespace std;int Three_Max[MAX][15], val[MAX], cnt[MAX];typedef str... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(132)
评论(0)
推荐(0)
摘要:
#include#include#include#include#define MAX 1111using namespace std;long long int dp[MAX], temp[MAX], ans;int main(){ int n; while(~scanf("%d", ... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(68)
评论(0)
推荐(0)
摘要:
思路:dp[i][j]表示str1的第i-1个字符和str2的第j-1个字符的最大的LCS,str[i-1] == str[j-1]时,dp[i][j] = dp[i-1][j-1] + 1 ; else : dp[i-1][j-1] = max(dp[i-1][j],dp[i][j-1]) .#i... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(104)
评论(0)
推荐(0)
摘要:
思路:dp[i][j]表示第i秒时,第j个位置获得馅饼的最大值,则dp[i][j] += max(dp[i-1][j],max(dp[i-1][j-1],dp[i-1][j+1])),另外由于起点是5,所以初始化时应该只留下这样的馅饼:abs(x-5) #include#include#includ... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(76)
评论(0)
推荐(0)
摘要:
思路:对于每个棋子有翻和不翻两种状态,翻奇数次等于翻1次,翻偶数次等于翻0次,因此16个棋子就有2^16种翻转的状态,枚举每个状态得到最小解。可以事先将翻转每个棋子后对应的状态保存起来。#include#includeusing namespace std;char s[5][5];int st[1... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(183)
评论(0)
推荐(0)
摘要:
思路:设dp[i][j]表示区间[i,j]的回文串的个数,那么有dp[i][j] = dp[j+1][i] + dp[j][i-1] - dp[j+1][i-1],如果str[i] == str[j],那么dp[i][j]还要加上dp[j+1][i-1] + 1;#include#include#i... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(121)
评论(0)
推荐(0)
摘要:
去年刚学acm时写了一道大数A+B,现在无聊回头看看发现当时写的太屎太长,所以顺便写个精简点的:#include#includeusing namespace std;string s1, s2;int main(){ while(cin >> s1 >> s2){ int j ... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(113)
评论(0)
推荐(0)
摘要:
思路:DP水,先排序,然后直接比较。#include#include#include#include#include#define MAX 1111using namespace std;class mouse{ public: int w, v, id; bool... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(83)
评论(0)
推荐(0)
摘要:
思路:openclock[i]记录到i位置打开大写键时的最小按键次数,closeclock[i]记录到i位置时不打开大写键时最小按键次数,详见代码。#include#include#include#include#define MAX 111using namespace std;int close... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(106)
评论(0)
推荐(0)
摘要:
思路:DP水题#include#include#include#define MAX 105using namespace std;int dp[MAX][MAX], a[MAX][MAX];int main(){ int c, n, maxn; /* freopen("in.c", "... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(75)
评论(0)
推荐(0)
摘要:
思路:DP水,dp[i][j]表示第i分钟到第j棵树的种数,dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1],再注意下边界就行。#include#include#include#define MAX 105using namespace std;int dp[MAX][M... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(78)
评论(0)
推荐(0)
摘要:
思路:dp[i][j]表示i个苹果,j个盘子的放的方案数,则有dp[i][j] = dp[i][j-1] + dp[i-j][j],dp[i][j-1]表示不是所有的盘子都放有苹果,dp[i-j][j],表示所有的盘子中都放入了苹果,这个前提是i>=j。i#include#includeusing ... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(93)
评论(0)
推荐(0)
摘要:
思路:贪心,每次都选结束位置小的,这样保证了最小程度的影响后面的串,所以一定是最优解。#include#include#include#include#define MAX 1111using namespace std;typedef struct Node{ int st, end, id... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(186)
评论(0)
推荐(0)
摘要:
思路:通过位运算来枚举集合,由于集合的互补性只需要枚举2^(n-1)个集合。#include#include#includeusing namespace std;int map[30][30];int main(){ int N, temp, flow, ans; //freopen(... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(105)
评论(0)
推荐(0)
摘要:
思路:求次短路,先spfa,再枚举各条边,次短路一定是最短路换一条边得到。#include#include#include#include#define MAX 100005#define INF 0xfffffffusing namespace std;typedef struct{ int... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(103)
评论(0)
推荐(0)
摘要:
思路:dp[i]表示a[i]之前连续的比a[i]大的数的个数,rdp[i]表示a[i]之后连续的比a[i]大的数的个数。如果dp[st] + rdp[end] >= end - st + 1,则是Yes,否则No。#include#include#include#define MAX 100005u... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(259)
评论(0)
推荐(0)
摘要:
#include#include#includeusing namespace std;int map[105][105], sum[105][105];int main(){ int n, maxn; /* freopen("in.c", "r", stdin); */ whil... 阅读全文
posted @ 2014-04-30 18:38
wangzhili
阅读(96)
评论(0)
推荐(0)
摘要:
思路:最短路,map[i][j] = d*(|x[i]-x[j]| + |y[i]-y[j]|) - add[i]#include#include#include#include#includeusing namespace std;long long int map[105][105],vis[1... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(96)
评论(0)
推荐(0)
摘要:
思路:使用优先队列,每次都取出先前状态中距离最短的状态,注意,入队的不是点也不是边,而是先前满足花费小于K的所有的可行状态,队列里面保存的是先前取的点的状态,这样每次弹出距离最小的状态进行更新,到最后得到的一定是满足距离最小且花费不大于K的解,一旦发现N点在状态中,就可以返回了,因为此时的状态就是最... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(252)
评论(0)
推荐(0)
摘要:
思路:DFS全图,记录每个牧场可以到达的牛的数量,若pa[v] == K,则所有牛可以到达。#include#include#include#define MAX 10005using namespace std;typedef struct{ int to, next;}Node;Node ... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(91)
评论(0)
推荐(0)
摘要:
思路:记忆化搜索 + DP#include#include#include#define MAX 105using namespace std;const int dir[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};int map[MAX][MAX], vis[MAX][M... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(99)
评论(0)
推荐(0)
摘要:
思路:BFS,最先找到的必定是最小解。#include#include#include#include#include#include#define MAX 11111using namespace std;int isprime[MAX], pre[MAX];queueq;void Chose_P... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(92)
评论(0)
推荐(0)
摘要:
思路:floyd + 位运算。map[i][j]的二进制位前26位表示i到j路径里面字母a-z的存在情况,为1说明该字母存在,为0不存在。#include#include#include#include#define MAX 205using namespace std;string str;int... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(87)
评论(0)
推荐(0)
摘要:
思路:ans = 每条边(u,v)*v的子树节点的w = 所有的dist[v]*w[v]之和;#include#include#include#include#define MAX 500005const long long int INF = 100000000000000;using name... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(83)
评论(0)
推荐(0)
摘要:
求最短路径的算法有许多种,除了排序外,恐怕是ACM界中解决同一类问题算法最多的了。最熟悉的无疑是Dijkstra,接着是Bellman-Ford,它们都可以求出由一个源点向其他各点的最短路径;如果我们想要求出每一对顶点之间的最短路径的话,还可以用Floyd-Warshall。SPFA是这篇日志要写的... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(221)
评论(0)
推荐(0)
摘要:
#include#include#include#define MAX 30 using namespace std; int map[MAX][MAX]; const int dir[4][2]={-1, 0, 1, 0, 0, -1, 0, 1}; int h, w, ans; void dfs... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(77)
评论(0)
推荐(0)
摘要:
/************************************************************************* > File Name: Gray.cpp > Author: wangzhili > Mail: ... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(149)
评论(0)
推荐(0)
摘要:
/************************************************************************* > File Name: phi.cpp > Author: wangzhili > Mail: ... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(143)
评论(0)
推荐(0)
摘要:
/************************************************************************* > File Name: extend_gcd.cpp > Author: wangzhili > M... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(86)
评论(0)
推荐(0)
摘要:
/************************************************************************* 2 > File Name: pow_mod.cpp 3 > Author: wangzhili 4 ... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(105)
评论(0)
推荐(0)
摘要:
#include#include#includeusing namespace std;const int MAX = 205;int dep, n, map[MAX][MAX];int dfs(int u, int v){ int max1, max2, path_max; max1 ... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(162)
评论(0)
推荐(0)
摘要:
思路:求割点#include#include#includeusing namespace std;const int v = 105;int edge[v][v];int bridge[v][v], cut[v];int low[v], dfn[v], vis[v];void cut_bridge... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(78)
评论(0)
推荐(0)
摘要:
思路:求树的高度。用并查集,不要压缩路径。#include#include#includeusing namespace std;int father[2005], cnt;int max(int x, int y){ return x > y ? x : y;}void init(int n... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(133)
评论(0)
推荐(0)
摘要:
#include#include#include#includeusing namespace std;int res[20][20], vis[20], pre[20];queueq;int N, M;bool bds(int s, int t){ memset(vis, 0, sizeof... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(137)
评论(0)
推荐(0)
摘要:
这个算法是基于FF方法,就是通过不断求残余网络的增广路来增广流量,直到找不到增广路为止。注意:每次找到增广路以后都要更新原网络。EK算法通过BFS寻找源S到汇T的一条最短路径,因此时间复杂度是O(VE^2).模板代码如下:#include#include#include#include#define... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(197)
评论(0)
推荐(0)
摘要:
#include #include #include #include using namespace std;const int maxn = 1001000;#define inf (1 ans) ans = tmp; tmp = p[s+k-1] - a + 1; ... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(119)
评论(0)
推荐(0)
摘要:
思路:用len[i]记录长度为i时的上升子序列对应的最小的那个数,每次插入一个数就更新len数组,使用二分查找进行修改操作,时间复杂度为O(nlogn),最后i的值就是上升子序列的最大长度。#include#include#includeusing namespace std;int a[10000... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(130)
评论(0)
推荐(0)
摘要:
思路:并查集,在查找,路径压缩的时候,用num[i]记录i被移动的次数,有:sum[i] += sum[father[i]]。#include#include#includeusing namespace std;int father[10005], num[10005], city[10005];... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(89)
评论(0)
推荐(0)
摘要:
思路:lazy标记,每次只记录最后那个数的增量,需要是再向前传递。#include#include#includeusing namespace std;long long int Delta[200005], a[200005];double sum;int main(int argc, char... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(94)
评论(0)
推荐(0)
摘要:
思路:并查集应用,处理是倒过来处理。#include#include#includeusing namespace std; int father[10005], a[100005], b[100005], block[100005]; int find(int x){ return x ==... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(78)
评论(0)
推荐(0)
摘要:
思路:据说是单调队列,我用线段树过的。。。#include#include#define MAX 1000005using namespace std;typedef struct{ int left, right, mid, min, max;}NodeTree;NodeTree node[... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(81)
评论(0)
推荐(0)
摘要:
#include#include#includeusing namespace std;struct cmp{ bool operator()(int x, int y) { return x > y; }};priority_queue, cmp>q;int mai... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(95)
评论(0)
推荐(0)
摘要:
#include#include#includeusing namespace std; #define N 200005 long long int ans, cow[N], lose[N]; int main(int argc, char const *argv[]) { int n; ... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(83)
评论(0)
推荐(0)
摘要:
思路:最大流算法,基于FF方法:1.Dinic:/************************************************************************* > File Name: Dith.cpp > Author: ... 阅读全文
posted @ 2014-04-30 18:37
wangzhili
阅读(75)
评论(0)
推荐(0)
摘要:
//*************************************************************************//// Author: wangzhili// Mail: wangstdio.h@gmail.com// Filename... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(131)
评论(0)
推荐(0)
摘要:
很久没做图论了,基本的数据结构都有点忘了,现在复习下,继续图论/******************************************************************/ Author:wangzhili title:test.c time: 2013年... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(132)
评论(0)
推荐(0)
摘要:
一 安装必要软件安装hostapd : sudo apt-get install hostapd安装DHCP: sudo apt-get install dhcp3-server二 配置HOSTAPD新建hostapd.conf 文件,将其存放到:/etc/hostapd/hostapd.con... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(501)
评论(0)
推荐(0)
摘要:
Sublime Text 2 的安装 :在官方网站下载Linux版本 Or 执行 # wget http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%202.0.1.tar.bz2得到一个“.tar.bz2”格式的压缩文件进行解压,并把解压包放到:#mv... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(124)
评论(0)
推荐(0)
摘要:
思路:线段树,每个节点记录是否当前区间只被一种颜色覆盖,如果是就将此颜色记录下来,如果不是,说明不是单色区间,那么就继续寻找其子区间,直到找到单色区间为止。其实很简单,因为整个区间必定是由一个个单色区间组成的!!!一开始这题提交的时候超时了,很费解,后来我把全局变量mid改成局部变量居然过了,不知道... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(86)
评论(0)
推荐(0)
摘要:
#include#include#define L(x) (x > 1; build(l,mid,L(k)); build(mid+1,r,R(k));}void insert(int pos,int val,int k){ if(pos >= node[k].left && po... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(93)
评论(0)
推荐(0)
摘要:
#include#include#define MAX 50000#define L(x) (x > 1; build(l,mid,L(k)); build(mid+1,r,R(k));}void insert(int pos,int num,int k){ if(pos >= n... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(97)
评论(0)
推荐(0)
摘要:
Color the ballTime Limit: 9000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6614Accepted Submission(s): 3470Prob... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(151)
评论(0)
推荐(0)
摘要:
位运算是指按二进制进行的运算。在系统软件中,常常需要处理二进制位的问题。C语言提供了6个位操作运算符。这些运算符只能用于整型操作数,即只能用于带符号或无符号的char,short,int与long类型。C语言提供的位运算符列表:运算符含义描述&按位与如果两个相应的二进制位都为1,则该位的结果值为1,... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(166)
评论(0)
推荐(0)
摘要:
Color the ballTime Limit: 9000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6609Accepted Submission(s): 3468Prob... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(145)
评论(0)
推荐(0)
摘要:
思路:线段树,节点区间的和由sum和add组成,更新:当区间正好匹配时就直接node[k].add += add,return,否则把和加在sum里,递归更新子区间。查找时:如果区间匹配就直接返回node[k].sum + (node[k].right - node[k].left + 1) * n... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(101)
评论(0)
推荐(0)
摘要:
思路:线段树,设计节点的时候不用记录该节点区间里面的sum,只需要记录每个区间里面的kind就行,(sum=R-L+1)*kind),这样更新的时候就看当前节点区间和插入的区间[L,R]的关系:1,如果当前节点区间的kind和插入区间的kind相同就直接结束UpdateTree()函数,不需要处理;... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(94)
评论(0)
推荐(0)
摘要:
对于初学系统编程,了解下系统的API是必要的;下面这个程序实现的是将自身程序复制到windows目录和系统目录;#include#include#includevoid copyself(){ char selfpath[MAX_PATH]{0}; char windowspath[MA... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(108)
评论(0)
推荐(0)
摘要:
最近学习了linux引导流程,简单总结下。我下面写的内容告诉了大家我们启动linux系统,从按下电源的那刻起计算机都做了什么,当然本文是针对linux系统而言的。第一步:固件firmware(CMOS/BIOS)POST (power on self test),加电自检过程,这是基于PC的就是说不... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(109)
评论(0)
推荐(0)
摘要:
Python很简洁,也很强大,作为兴趣,值得一学!下面这个程序实现的是从一个网站上下载图片,根据自己需要可以进行修改import reimport urllibdef gethtml(url): page = urllib.urlopen(url) html = page.read() ... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(241)
评论(0)
推荐(0)
摘要:
思路:KMP,但要对其进行变形,当找到失败位置时,要继续考察该位置,一直向前找到字符串首不能再向前找,因为我们不只要计算该子串本身,我们还要计算该子串包含的其他子串,因为这些子串都是原串的子串,这是显然的。#include#includeint fail[200005];int sum[200005... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(88)
评论(0)
推荐(0)
摘要:
初次运行 Git 前的配置一般在新的系统上,我们都需要先配置下自己的 Git 工作环境。配置工作只需一次,以后升级时还会沿用现在的配置。当然,如果需要,你随时可以用相同的命令修改已有的配置。Git 提供了一个叫做 git config 的工具(译注:实际是git-config命令,只不过可以通过gi... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(100)
评论(0)
推荐(0)
摘要:
思路: AC自动机#include#include#includetypedef struct Node_Tree{ int cnt; struct Node_Tree *child[26]; struct Node_Tree *fail; }Node; Node *root;... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(90)
评论(0)
推荐(0)
摘要:
目前的搜狗输入法 for Linux 是Linux Deepin 社区版的测试版,基于Fcitx 框架。话不多说,直接上。准备工作:卸载Ubuntu默认的ibus输入法:sudo apt-get remove ibus然后添加Fcitx 源:sudo add-apt-repository ppa:f... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(478)
评论(0)
推荐(0)
摘要:
统计难题Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 131070/65535 K (Java/Others)Total Submission(s): 15031Accepted Submission(s): 6436Problem Desc... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(122)
评论(0)
推荐(0)
摘要:
思路: KMP#include#includechar a[1005], b[1005];int fail[1005];int lena, lenb;int cnt;void getfail(){ fail[0] = -1; int i, j; for(i = 1, j = -1;... 阅读全文
posted @ 2014-04-30 18:36
wangzhili
阅读(81)
评论(0)
推荐(0)
浙公网安备 33010602011771号