05 2013 档案
摘要:3维树状数组,将单点更新转变为区间更新。 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 using namespace std; 6 #define LL __int64 7 #define N 50002 8 int p[11][11][50011]; 9 int num[50011];10 int n;11 int lowbit(int t)12 {13 return t&(-t);14 }15 void ins
阅读全文
摘要:题目链接离线算法,以前做过一个,非常神奇。先把所有的区间,按Y排序,再按X排,然后算每一个区间,如果遇到了相同的就把前一个点更新一下-num[le],当前点插入。如果相同直接插入。再区间求和,记录结果。 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 using namespace std; 6 #define N 200001 7 #define LL __int64 8 struct node 9 {10 int x,y,
阅读全文
摘要:题目链接每一个必胜点P,肯定可以走到一个N点,N点的下一步,全是P点。递推出小数据,找规律,很明显。 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 int dp[101][101]; 6 char s1[10001],s2[10001]; 7 int main() 8 { 9 // int i,j,k,z,n,m;10 // memset(dp,-1,sizeof(dp));11 // for(i = 1;i <= 100;
阅读全文
摘要:好久没写了,单调队列。 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 int dp[2000001],p[2000001],sum[2000001]; 6 int que[2000001]; 7 int main() 8 { 9 int n,m,i,str,end;10 scanf("%d%d",&n,&m);11 for(i = 1;i <= n;i ++)12 {13 scanf(&q
阅读全文
摘要:题目链接模版题,写错了,wa好几次。。 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 #define LL __int64 6 int dp[1001]; 7 int fib[21]; 8 int sg(int x) 9 {10 int flag[101],temp,i;11 if(dp[x] >= 0)12 return dp[x];13 memset(flag,0,sizeof(flag));14 for(i = 1;i
阅读全文
摘要:先暴力出sg函数来,会发现sg(x) = x,然后枚举每一种走法,看看异或结果是否为0。因为temp^temp = 0,所以这样可以直接判断。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 int n; 7 int p[101]; 8 int main() 9 {10 int i,temp,ans,num;11 while(scanf("%d",&
阅读全文
摘要:这个题和传纸条差不多,但是我没想到。。还是在解决只走一次时候,没想到怎么办。dp[i][j]代表一条走到i和另一条走到j的最多结点。假如某点走了两次那么他一定是从dp[i][i]走来的,但是dp[i][i] = 0,所以根本没有这种情况。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: tour 5 */ 6 #include <iostream> 7 #include <cstdio> 8 #include <cstring> 9 #include <algorithm>10 #include <map>
阅读全文
摘要:SG函数模版,学习ing... 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 int dp[10001],n; 7 int p[101]; 8 int sg(int x) 9 {10 int i;11 int flag[101];12 memset(flag,0,sizeof(flag));13 if(dp[x] != -1)14 return dp[x];15 if(x
阅读全文
摘要:打表水过。看的题解,置换的那个优化完全没有看懂。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: latin 5 */ 6 #include <cstdio> 7 #include <iostream> 8 using namespace std; 9 int r[11][11],c[11][11];10 int ans,n;11 void dfs(int x,int y)12 {13 int xx,yy,i;14 if(x > n-1)15 {16 ans ++;17 return ;18 }19 ...
阅读全文
摘要:最大子矩阵问题,USACO上貌似好几个把。。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: bigbrn 5 */ 6 #include <iostream> 7 #include <cstring> 8 #include <cstdio> 9 #include <cstdlib>10 using namespace std;11 int dp[1001][1001],r[1001][1001],c[1001][1001];12 bool o[1001][1001];13 int main()14 {15 int n
阅读全文
摘要:我以前的Tarjan模版,全都敲错了。。。一个v写成了u,而且都AC了。。。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: schlnet 5 */ 6 #include <iostream> 7 #include <cstring> 8 #include <cstdio> 9 #include <cstdlib> 10 using namespace std; 11 #define N 10001 12 #define M 500001 13 struct node 14 { 15 int u,v,next; 16
阅读全文
摘要:坐标不全是左上角,右下角的。2Y,怎么可以写的这么麻烦。。。暴力水过。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: window 5 */ 6 #include <iostream> 7 #include <cstdio> 8 #include <cstring> 9 #include <cmath> 10 #include <algorithm> 11 #include <vector> 12 #include <string> 13 #include <queue>
阅读全文
摘要:理解错题意了。。。写的很麻烦,而且900+卡过。。。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <string> 6 #include <cmath> 7 using namespace std; 8 #define eps 1e-6 9 struct cir 10 { 11 int x,y,r; 12 } p[1001]; 13 int flag[1001]; 14 in
阅读全文
摘要:像是背包的逆问题,给一个体积,然后给一些物品,求用最少的物品组成这个体积,输出字典序最小的集合。物品和体积都不小,完全没什么思路,印象中DD大神的背包9讲里,有USACO里背包问题的解析,然后发现暴力然后DP就可以过,然后。。。就水过了。。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: milk4 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <cmath> 9 #include <algorithm>10 #include <iostream
阅读全文
摘要:好扯淡。。。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: wissqu 5 */ 6 #include <iostream> 7 #include <cstdio> 8 #include <cstring> 9 #include <queue> 10 #include <map> 11 #include <ctime> 12 #include <cmath> 13 #include <algorithm> 14 using namespace std; 15 char
阅读全文
摘要:搞了一下午,枚举顺序要注意....然后数据类型.... 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 #include <map> 6 #include <ctime> 7 #include <cmath> 8 #include <algorithm> 9 using namespace std;10 #define LL long long11 LL dp[1000001];1
阅读全文
摘要:比赛的时候,大体还是想出来了,有些细节没想好,虎哥提示了下,我写写代码,过了样例,就过了。。。智商拙计啊。。。看题看了好一会,才看懂题意,想了好一会,最后还没写出来。。。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 #include <map> 6 #include <ctime> 7 #include <cmath> 8 #include <algorithm> 9 usin
阅读全文
摘要:学习模拟退火,讲解看这里:http://www.cnblogs.com/heaad/archive/2010/12/20/1911614.html代码看的山大一个大神的博客:http://3214668848.blog.163.com/blog/static/48764919200991894621558/代码里就一个随机数,实现模拟退火算法的代码,比较好懂的。。。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: fence3 5 */ 6 #include <iostream> 7 #include <cstdio> 8 #include
阅读全文
摘要:DFS,1Y啊。。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: snail 5 */ 6 #include <iostream> 7 #include <cstdio> 8 #include <cstring> 9 #include <queue>10 #include <map>11 #include <cmath>12 #include <algorithm>13 using namespace std;14 int a[4] = {0,1,-1,0};15 int b[4]
阅读全文
摘要:先写了暴力,过了10+组,后来想了想,发现这个跟求最长公共子序有点相似啊。改改了状态转移,wa在第2组,然后注意了一下,包含的情况,乱改的一下,就过了。。。dp[i][j] 表示以i为结尾,j结尾最长的"主题" 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: theme 5 */ 6 #include <iostream> 7 #include <cstdio> 8 #include <cstring> 9 #include <queue>10 #include <map>11 #inc
阅读全文
摘要:把所有的连通块,左上角,右下角的坐标当作一个矩形存起来。然后枚举,跟之前的是不是相同。注意:连通块转化成矩阵的时候,只有一起连通的的点,在小的矩形里才为1,而不是str[i][j] =='1',这里错了次。。写的很麻烦。。 1 /* 2 ID:cuizhe 3 LANG: C++ 4 TASK: starry 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <iostream> 9 using namespace std; 10 struct node 11 { 12 int
阅读全文
摘要:注意传参的 类型。。。模版啊。。。 1 /* 2 ID:cuizhe 3 LANG: C++ 4 TASK: fc 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <cmath> 9 #include <queue>10 #include <iostream>11 #include <algorithm>12 using namespace std;13 #define eps 1e-614 struct Point15 {16 double x,y;17
阅读全文
摘要:终于结束了第4章。。倒数第二个题,卡了2个月。。。这个题,实现起来,还挺麻烦的,看懂题意,建好图,就是裸的拓扑排序了。 1 /* 2 ID:cuizhe 3 LANG: C++ 4 TASK: frameup 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <cmath> 9 #include <queue> 10 #include <iostream> 11 using namespace std; 12 int lx[30],ly[30],rx[30],ry[30]
阅读全文
摘要:第一二问,可以通过*1001+1,最后ans/1001 ans%1001来解决,第三问,看题解后完全无想法,然后找了一种水过的办法,水过了。。这种做法应该是错的。 1 /* 2 ID:cuizhe 3 LANG: C++ 4 TASK: milk6 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <cmath> 9 #include <queue>10 using namespace std;11 #define LL long long12 LL INF;13 LL flow[2
阅读全文
摘要:题目链接那场1个题就晋级的初赛,我当时搞A题,弄了一个多小时。。。这个DP,在各种瞎搞,修改之后,过了。。。 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <map> 5 #include <iostream> 6 using namespace std; 7 #define INF 100000000 8 int dp[201][201]; 9 int t[101],z[101];10 int main()11 {12 13 int N,
阅读全文
摘要:题目链接我做的伤心了,不知是模版效率低,还是错了,交上就是TLE,找了份别人的代码,改了好几下终于过了。。 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <map> 5 #include <iostream> 6 using namespace std; 7 #define INF 0x3fffffff 8 char food[201][201],drink[201][201]; 9 struct node 10 { 11 int u,v,
阅读全文
摘要:题目链接第一个二维的,注意一点如果num + 1 > w,num = w 这样就可以节约空间了,因为假如经过很多条边而且是最短路的话,无法存储。。 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 using namespace std; 5 #define INF 0x7fffffff 6 struct node 7 { 8 int u,v,next,w; 9 }edge[300001];10 int first[5001];11 int t,n;12 int dis[5001
阅读全文