Shirlies
宁静专注认真的程序媛~
03 2012 档案
hdu 2874
摘要:痛苦啊。。。折磨我好长时间啊,不过总算把错误给搞出来了,也学到了一点东西。。。。。。哎,可是这折磨貌似太长了。。。。。。。。。。。。。。。。。。。。首先用的是动态邻接表,起初WA,之后MLE,晕,不过知道了动态邻接表为什么会MLE了:起初分配的内存没有释放,而且题目说有大量的输入,这样就会越积越多。。。然后就是用vector,也是一直WA,郁闷,和网上的代码对比之后,改了一通,A了之后,忽然知道哪里错了,就是当是同一个点的时候,那个vis数组要放在lca函数的开头,如果放中间,因为我是首先判断有没有答案的,所以如果是同一个点的话,如果vis放中间的话,同一个点是无法判断的它之间的距离的。。。。 阅读全文
posted @ 2012-03-31 22:08 Shirlies 阅读(842) 评论(0) 推荐(0) 编辑
hdu 2586【lca的tarjan算法】
摘要:哈哈,让我把错误给找出来了,c++ 31ms,(*^__^*) 嘻嘻……有点成就感,也有点烦闷,单步调试终于把错误搞出来了,可是这个是递归诶,单步调试,我的时间啊。。。。~~~~(>_ 2 #include 3 4 const int maxn = 40010; 5 6 struct node 7 { 8 int tag; 9 int w; 10 struct node *next; 11 }*temp; 12 13 struct head 14 { 15 struct node *next; 16 }; 17 head pnt[maxn... 阅读全文
posted @ 2012-03-27 17:23 Shirlies 阅读(244) 评论(0) 推荐(0) 编辑
hdu 1166【树状数组】
摘要:一道简单的树状数组,但是存在坑爹的问题。。。是我自己的问题。。。。。。~~~~(>_<)~~~~首先说一下输出,输出案例,是在输入那些阵营的人数之后在输出(再次表示不满,acm就一定要有案例输出吗,这个问题输出错了竟然判wa,害人不浅,我根本就没有想到这里会出错,浪费精力。。。~~~~(>_<)~~~~ )第二,我判别了一下人数删除时是否符合要删除的数量时就错了。。。。。。有问题吗?难道你要别人减去的人比本来的人数还要多。。。。。。你很喜欢负债吗?(~ o ~)~zZView Code 1 #include <cstdio> 2 #include <c 阅读全文
posted @ 2012-03-25 11:28 Shirlies 阅读(363) 评论(0) 推荐(0) 编辑
hdu 1892【二维树状数组】
摘要:O(∩_∩)O哈哈~二维树状数组被我搞出来了,太开心了,第一道二维树状数组,(~ o ~)~zZ虽然中途还是出问题了,就是S询问的时候我没有考虑坐标的大小问题,还是搜了别人的代码才知道的,看来自己考虑问题不周到,~~~~(>_<)~~~~View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int book[1005][1005]; 6 int size = 1002; 7 void insert(int x,int y,int num) 8 { 阅读全文
posted @ 2012-03-23 22:06 Shirlies 阅读(290) 评论(0) 推荐(0) 编辑
hdu 1053Entropy
摘要:(顺便说一下,前面的一道Box Relations,这一题我是根据别人的代码写的,构造那个图很难的说,我也是品味了好久才品出真味来的。http://blog.csdn.net/me4546/article/details/6576517)huffman编码是也一用到指针就容易出错,~~~~(>_<)~~~~ 该死的,是我对指针没有理解清楚吗?~_~View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 using namespace std; 5 6 stru 阅读全文
posted @ 2012-03-22 13:24 Shirlies 阅读(317) 评论(0) 推荐(0) 编辑
uva 10341
摘要:又有好久没有写博客了,主要是没怎么做题,汗……有点小忙吧~~~这一题坑了我,我搞不懂编译器咋这么差,这等错误都找不出来,我勒个去啊~~~害惨我了……~~~~(>_<)~~~~View Code 1 #include <cstdio> 2 #include <cmath> 3 4 const double er = 1e-6; 5 double p,q,r,s,t,u; 6 7 inline double get_value(double x) 8 { 9 return p*exp(-x)+ q*sin(x) + r*cos(x) + s*tan(x) + t 阅读全文
posted @ 2012-03-21 22:01 Shirlies 阅读(294) 评论(0) 推荐(0) 编辑
uva 10761
摘要:用两个数组存储,再排序就OK了,如果有1 2,没有2 1,那么第二个数组排序后肯定没有1 2,那么就NO了~~~View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 struct per 6 { 7 int start,end; 8 }; 9 per p[500010],rp[500010];10 11 bool cmp(per p1,per p2)12 {13 if(p1.start == p2.start)14 return p1.end < p2 阅读全文
posted @ 2012-03-15 15:57 Shirlies 阅读(201) 评论(0) 推荐(0) 编辑
uva 10391字典树
摘要:View Code 1 #include <cstdio> 2 #include <cstring> 3 4 const int sonnum = 26; 5 char word[120005][30]; 6 struct trie 7 { 8 bool term; 9 struct trie *son[sonnum];10 };11 12 trie* create_trie()13 {14 trie *temp = new trie;15 temp -> term = false;16 for(int i = 0;i <sonnum;i++)17 ... 阅读全文
posted @ 2012-03-15 15:06 Shirlies 阅读(278) 评论(0) 推荐(0) 编辑
hdu 1198
摘要:一看到这一题,我真没想到用并查集做,坑啊,看看别人的大致思路才知道用并查集可以做,唉,看来是自己太弱了~~~View Code 1 #include <cstdio> 2 #include <cstring> 3 4 int pipe[11][4]={{1,0,0,1},{1,1,0,0},{0,0,1,1}, 5 {0,1,1,0},{1,0,1,0},{0,1,0,1},{1,1,0,1},{1,0,1,1}, 6 {0,1,1,1},{1,1,1,0},{1,1,1,1}};//将每个都编号了,并且用上了边 7 int f[3000]; 8 int map[300 阅读全文
posted @ 2012-03-10 00:02 Shirlies 阅读(461) 评论(0) 推荐(0) 编辑
hdu 2149
摘要:sg值但是这一题要注意一点,就是N值大于等于M值时考虑。View Code 1 #include <cstdio> 2 #include <cstring> 3 4 int sg[1101]; 5 int mex[1101]; 6 int m,n; 7 8 void get_sg() 9 {10 int i,j;11 sg[0] = 0;12 for(i = 1;i <1101;i ++)13 {14 memset(mex,0,sizeof(mex));15 for(j = 1;j <=n ;j ++)16 ... 阅读全文
posted @ 2012-03-09 21:25 Shirlies 阅读(235) 评论(0) 推荐(0) 编辑
hdu 1848
摘要:求sg值就行了View Code 1 #include <cstdio> 2 #include <cstring> 3 4 int fib[1000]; 5 int sg[1100]; 6 int mex[1000]; 7 int num_fib; 8 9 void cal_fib()10 {11 fib[0] = 1;12 fib[1] = 1;13 int i;14 for(i = 2;i < 1000;i ++)15 {16 fib[i] = fib[i-1] + fib[i-2];17 if(fib[i] >... 阅读全文
posted @ 2012-03-09 20:55 Shirlies 阅读(375) 评论(0) 推荐(0) 编辑
hdu 2473
摘要:这一题是与并查集删除节点有关的,我想不出来怎么做,看了别人的解题思路,也依葫芦画瓢写了份代码,代码就没有必要贴了,说说自己看了别人解题思路后自己的理解吧。这一题是要求我们删除集合中的数并另外占一个集合,大家的思路基本上都是:用虚拟节点做父节点(之前的并查集,我们都是用自己做自己的父节点),我们修改的也只是与一个数关联的父节点。说是这样说,但是方法要想出来还是要费一番周折的。提供两种链接代码http://www.cppblog.com/MiYu/archive/2010/08/26/124771.htmlhttp://www.cnblogs.com/fornever/archive/2011/1 阅读全文
posted @ 2012-03-09 15:15 Shirlies 阅读(664) 评论(0) 推荐(0) 编辑
hdu 1850
摘要:这是一道关于博弈的题目,这一题挺不错的,如果知道了nim游戏异或的道理,这一题是比较好写的。Nim游戏的局面(a1,a2,...,an),它是P-position当且仅当a1^a2^...^an=0,其中^表示异 或(xor)运算。•对于某个局面(a1,a2,...,an),若a1^a2^...^an==k(k>0)•一定存在某个合法的移动,将ai改变成ai'后满足 a1^a2^...^ai'^...^an=0•一定存在某个ai,它的二进制表示在k的最高位上是1 (ai^k<ai 成立)•将ai改变成ai'=ai^k a1^a2^...^ai'^.. 阅读全文
posted @ 2012-03-09 09:36 Shirlies 阅读(950) 评论(2) 推荐(0) 编辑
hdu 1847
摘要:做完之后,想看看别人是怎么做的,翻了一下别人的代码,晕,那个简洁啊,直接模3……我还是贴我自己的代码吧,我是想求SG值来着的……View Code 1 #include <cstdio> 2 3 int index[11]={1,2,4,8,16,32,64,128,256,512,1024}; 4 int n; 5 int vic[1002]={0}; 6 7 int main() 8 { 9 int i;10 11 for(i=1;i<1002;i ++)12 {13 int flag = 0;14 for(int j=0;j<... 阅读全文
posted @ 2012-03-07 13:15 Shirlies 阅读(526) 评论(0) 推荐(0) 编辑
hdu 3635
摘要:题意:起初球i是被放在i号城市的,在年代更迭,世事变迁的情况下,球被转移了,而且转移的时候,连带该城市的所有球都被移动了:T A B(A球所在的城市的所有球都被移动到了B球所在的城市),Q A(问:A球在那城市?A球所在城市有多少个球呢?A球被转移了多少次呢?)。这一题还是蛮有意思的,虽然第一次写的时候超时了,因为我没有利用好查找函数的递归性,在合并的时候用一个循环将本来可以在查找时就合并好的,又另外处理的。View Code 1 #include <cstdio> 2 #include <string> 3 #define MAX 10010 4 5 int rank 阅读全文
posted @ 2012-03-06 16:11 Shirlies 阅读(1385) 评论(1) 推荐(1) 编辑
hdu 1811
摘要:不知道怎么下手,真没有想到这一题就来拓扑排序,本来看到这一题是觉得要用拓扑的,可是这一题是属于并查集的,并且也不知道怎么用拓扑来处理,汗,搜搜,发现竟然还可以用队列来实现拓扑,精神!是参考以下代码的:http://972169909-qq-com.iteye.com/blog/1052820 阅读全文
posted @ 2012-03-05 22:12 Shirlies 阅读(593) 评论(0) 推荐(0) 编辑
hdu 1829
摘要:这一题是听同学讲过例题后,现在做起来,感觉特别有意思。rank表示当前点到父节点的距离,如果距离是奇数,那么这两个就是异性,否则是同性,所以可以用%2判定他们之间的性别。以下注释是根据自己的理解写的,其实也不太清楚自己的理解是否是正确的^_^View Code 1 #include "stdio.h" 2 #include "string.h" 3 4 int f[3000]; 5 int rank[3000]; 6 7 int find(int x) 8 { 9 int t;10 if(x==f[x])11 return x;12 13 t=fi... 阅读全文
posted @ 2012-03-05 11:13 Shirlies 阅读(1022) 评论(2) 推荐(1) 编辑
hdu 3500
摘要:题意:就是用一个球a去撞另外一个球b(如果两个相邻是撞不了的),球a停在球b前,球b被撞出去了,少了一个球咯,如果一行有多个球,那么就一个传一个咯,题目要求的结果是最后只剩下一个球。每次都得从头开始搜,我认为是不能只用结构体存储'O'的位置的,必须得用数组存储,因为,每次撞球后位置改变了,结构体存储的点的顺序是会变化的,而下一次搜索又是必须得按顺序开始搜的(即从左上角开始),如果对变化后的结构体排序的话,那么回溯回来又怎么办?反正我是想不到办法了,然后改成数组存储了。我写的挺复杂的,其实思路挺简单的。View Code 1 #include <iostream> 2 阅读全文
posted @ 2012-03-04 23:09 Shirlies 阅读(321) 评论(0) 推荐(0) 编辑
hdu 1426
摘要:数独,O(∩_∩)O哈哈~做了这道,以后什么数独就可以直接得出答案了……View Code 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 5 int sudo[9][9]; 6 int flag; 7 8 void dfs(int a,int b); 9 int is_repeat(int i,int j,int k); 10 11 int main() 12 { 13 char a; 14 int cas=0; 15 while(cin>>a) 16 ... 阅读全文
posted @ 2012-03-02 19:22 Shirlies 阅读(454) 评论(0) 推荐(0) 编辑
uva 10305
摘要:这是一道纯粹的拓扑排序,刘汝佳的《算法入门经典》p110里面有例题. 1 #include "stdio.h" 2 #include "string.h" 3 4 int task[102][102]; 5 int vis[102]; 6 int n,m; 7 int k; 8 int topo[102]; 9 10 int dfs(int u);11 void toposort(void);12 13 int main()14 {15 int i;16 int a,b;17 while(scanf("%d%d",&n,&am 阅读全文
posted @ 2012-03-01 22:38 Shirlies 阅读(893) 评论(0) 推荐(0) 编辑
hdu 2094
摘要:这一题是参考别人的,但是此题用到了映射,第一次用映射,感觉到了stl的方便之处http://blog.csdn.net/acb0y/article/details/5865561 阅读全文
posted @ 2012-03-01 22:33 Shirlies 阅读(172) 评论(0) 推荐(0) 编辑