zhouxiaojie的博客
zhouxiaojie · 共 12 篇文章
spoj 11575. A Famous Equation
https://www.spoj.pl/problems/EQ2/ 我的做法在这个网站上能过,但是过不了杭电的,郁闷了很久。 #include #include #include using namespace std; int a,b,c; char str; int aa,bb,cc; long long suma,sumb,sumc; long long f; int main() { int i,j,k,t,cas=0,ss,tt; while(scanf("%s",str)!=EOF) { cas++; int len = strlen(str); aa=1;bb=1;cc=1;k…
2012-11-06 22:55 · spoj · 评论(0)
poj 2157 Maze
bfs. 先找小写字母,标记每种小写原来总共的exsit, 能过搜到的小写字母用f标记,搜到一个,就加一,如果搜到的是大写字母,判断f>exsit 如果是,入队,如果不是,先保存起来,之后每次判断一下,如果满足f>exsit就入队。如果搜到‘G’结束搜索,得出答案。 #include #include #include #include using namespace std; char s; int f,exsit; int sx,sy,n,m; int vis; int go={-1,0,1,0,0,1,0,-1},flag=0,num=0; struct array { int x,y…
2012-10-03 10:22 · poj · 评论(0)
poj 3400 Dropping the stones
错了很久,终于明白了,原来题意理解错了,总以为输入的第一个球一定投入A, 原来第一个投的球不一定是输入的第一个。 用 next_permutation 写的: #include #include #include #include using namespace std; int a,b,c; struct array { int x,y; }s; int main() { int n,d,i,j; scanf("%d%d",&n,&d); { int sa=0,sb=0; for(i=1;i<=n;i++) { scanf("%d%d",&s*.x,&s*.y); } for(i=0;i<…
2012-09-28 23:23 · poj · 评论(0)
poj2886Who Gets the Most Candies?
个人觉得从一个位置下一个位置是关键,然后用树状数组就简单了。 之前举例子推推导公式时只用一个参数,一直凑不出来,后来用两个参数,一个是这列数中原来的位置,另一个是前一个位置的人跳出后,下一个人的前面和自己一共的人数。我用d表示前一个参数,k表示后一个参数。 这一题还学到反素数,真是很有用的东西。 反素数打表就行,然后线段树+二分, 还有我改得最多的main()函数: int aa= {1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,453…
2012-09-15 14:58 · poj · 评论(0)
1182食物链
用并查集,方法模仿POJ2492A Bug's Life, 这题是2 n个数,如果a和b是异性,那么a和b+n,b和a+n是同性,这样在判断a和b是否是同性时可以通过a+n,或b+n来判断。 而1182 这题是类似的方法,如果 b 被 a 吃,那么 a 和 b+n , a+n 和 b+2 n ,b 和 a+2*n 是同类。如果输入有“1 A B”, 如果A,B不同类 或 B 吃 A 则这句话是假的。 #include int pre; void init(int n) { int i; for(i=0;i<=n 3;i++) { pre =-1; } } int find(int x) { …
2012-08-02 12:54 · poj · 评论(0)
zoj 3631Watashi's BG
主要错在一个地方: 本以为输入的每个数大于M就一定要被排除掉,但是,如果排除掉,在dfsI()里 大于M的数可以不取,而step却可以加一,这种情况漏掉了。 #include #include using namespace std; int N,M,Max,k; int a; int flag; void dfs(int step,int sum) { if(flag)return; if(sum>M)return; //if(a>M)return; if(step>=k) { Max = max(Max,sum); return ; } if(sum+a<=M) Max = max(Ma…
2012-07-29 23:39 · zoj · 评论(0)
poj3678Katu Puzzle
最近在学2-sat,也就做到了这题。开始建图建错了,用了网上模型才过。 然后我讲讲我对这个模型的理解: A and B == 0: 建边A->!B, B->!A A and B == 1: 建边!A->A, !B->B A or B == 0: 建边A->!A, B->!B A or B == 1: 建边!A->B, !B->A A xor B == 0: 建边A->B, B->A, !A->!B, !B->!A A xor B == 1: 建边!A->B, !B->A, A->!B, B->!A 因为如果一个命题成立,它的逆否命题一定成立。0->1为真,而1->0为假。 A and B =…
2012-07-27 22:59 · poj · 评论(0)
1129Channel Allocation
按A,B,C……的顺序搜索,让每个字母对应一个数,表示到这个字母时可以用的最少的频道,最后一个字母对应的最少的频道即要求的结果, 比如已经搜完了C,C对应的数是m, 轮到搜索D, D从1-m中选一种频道,如果这个频道和与D相关的字母的频道都不同,再往E搜, 如果不存在这样的频道,则D 用m种外的频道, D 对应的最少频道数即m+1。 #include #include #include using namespace std; int a,b,n; int small = 10000000; void dfs(int nn,int mm) { int i,j,k,g; k=0; if(nn=…
2012-07-15 21:24 · poj · 评论(0)
2676Sudoku修改
没想到,在写完上一篇博文后,在代码上加了句,提交ac了。 原来是因为当数独有多种答案,我的代码会把所有可能都输出,而题目只要求一种, 所有用gs标记,如果已经输出,就停止。
2012-07-15 21:17 · poj · 评论(0)
2676Sudoku
这个题自己写的样例能过,但是提交总是output limit exceed。还没想明白到底哪里错了, 走过路过的帮忙看看哪里出问题? #include #include #include using namespace std; int a,n; int hen,shu,kuai; struct M { int x,y,k; }s; int f(int xx,int yy) { if(xx>=1&&xx<=3&&yy>=1&&yy<=3)return 1; else if(xx>=4&&xx<=6&&yy>=1&&yy<=3)return 4; else if(xx>=7&&xx<=9&&y…
2012-07-15 21:08 · poj · 评论(0)
1029False coin
一开始看样例以为假币总是比真币重,假币总在较小的那堆里。 满足一 :某币在小于,或大于中出现的次数与不等关系出现的次数相同, 二:不在有“=”的比较中出现。 则可能是假币。满足一二的只有一个则输出,否则输出0.
2012-07-15 14:16 · poj · 评论(0)