摘要: 这道题根同性恋那道题相当像无非就是看他有没有合并过、记录合并之后的那个点的关系罢了。View Code //AC代码1#include <stdio.h> #include <stdlib.h> int set[100005],num[100006],h[100005]; int find(int x) { if(x!=set[x]) { int y = set[x]; set[x] = find(set[x]); num[x] = (num[x]+num[y])%2;//一定要写这个%2不知道为什么不加%2他就wa加上就ac我郁... 阅读全文
posted @ 2012-07-26 16:06 某某。 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 首先看到这个题号的时候我想起了好公民,韩寒同学和他的不死鸟= =本人二蛋一枚,近日做了些并查集的东西但是一直不太明白怎么才能查节点路径,而且觉得要是迭代的时候加了r[x]的话会出现多加的情况,后来经网上高人指点(觉得还是好人多,虽然自己确实不想做好人了= =)明白了~一下是高人话语~voidmerge(int a,int b){ father[a]=b; place[a]+=number[b]; number[b]+=number[a];}intFind(int a)//检查找和路径压缩{if(father[a]==-1)return a;int tmp=father[a];... 阅读全文
posted @ 2012-07-26 10:26 某某。 阅读(291) 评论(0) 推荐(0) 编辑
摘要: 跟那个排序二叉树的那个静态树一样,不大习惯静态的,但是不静态会tle,94msView Code #include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct node{ int flag; int next[11];}trie;int leap,count;trie tr[100010];new_node(){ int i; count++; tr[count].flag = 0; for(i = 0;i < 10;i++) tr[count].next[i] ... 阅读全文
posted @ 2012-07-26 01:02 某某。 阅读(171) 评论(0) 推荐(0) 编辑
摘要: View Code // Little Bishops (棋盘上的象)// PC/UVa IDs: 110801/861, Popularity: C, Success rate: high Level: 2// Verdict: Accepted // Submission Date: 2011-06-19// UVa Run Time: 0.024s//// 版权所有(C)2011,邱秋。metaphysis # yeah dot net//// n * n 的棋盘可以最多放置多少个象而不互相冲突?我是这样考虑的,因为象的吃子方式为// 对角线吃子,则在棋盘上放置一个象后,它要么占据一条对 阅读全文
posted @ 2012-07-25 19:12 某某。 阅读(455) 评论(0) 推荐(0) 编辑
摘要: View Code #include<stdio.h>void process(int a[],int k){ int i; for(i = 1;i <= k;i++) printf("%d ",a[i]); puts("");}int construct(int a[],int k,int n,int c[]){ int i; int pre[100]; for(i = 1;i < 100;i++) pre[i] = 0; for(i = 1;i < k;i++) pre[a[i]] = 1; int n2 = 0; f. 阅读全文
posted @ 2012-07-25 15:42 某某。 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 给你一个字符长度N,然后给你一个各个字符对应的数值,然后输出长为n总和最小的字符串、并且要按字点顺序输出。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>char vowels[] = "AUEOI";char conson[] = "JSBKTCLDMVNWFXGPYHQZR";char odd[220];char even[220];int cmp(const void *a,const void *b){ return (*(char 阅读全文
posted @ 2012-07-24 21:22 某某。 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 这道题WA了很多次,最后发现输出的时候第三位要带上‘-’ = =...而且UVA很坑爹的是不能用strcmpi,strupr!!!!View Code #include<string>#include<stdlib.h>#include<cstdio>#include<stdio.h>#include<string.h>typedef struct node{ char num[35]; int count;}tele;tele tel[100005];int cmp(const void *a,const void *b){ ret 阅读全文
posted @ 2012-07-24 16:53 某某。 阅读(216) 评论(0) 推荐(0) 编辑
摘要: View Code #include<stdio.h>#include<string.h>typedef struct node{ int score; int win; int lose; int jball; int wpoint; int zchang; int tie; int wingame; int losegame; char name[35];}team;team teams[1005];int search(char name[],int n){ int i; for(i = 0;i < n;i++) ... 阅读全文
posted @ 2012-07-24 11:19 某某。 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 这道题是自己写着玩的,看看能不能掌握简单的回溯,是挑战编程上的一个小程序自己打下来的。留个纪念。还有一个回溯是一个牛喝水的那一道。八皇后就不多少了,我想基本提到回溯法的树上都会提及八皇后和它的代码。View Code #include <stdio.h> #include <stdlib.h> int leap = 0; void process(int a[],int k) { printf("{"); int i; for(i = 1;i <= k;i++) if(a[i]) printf(" %d",i); print 阅读全文
posted @ 2012-07-22 20:05 某某。 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 题目连接:http://poj.org/problem?id=2492大意大概解释给你一个t代表多少个case,然后有n个虫子,m个谁喜欢谁,这种虫子跟咱们一个货色只有两种性别,男的,或者是母的,然后就是让你算算有没有高搞基或者是百合。大体思路就是用并查集,然后用一个数组算这个节点到根节点的长度,然后看相同具有相同祖先的是不是有相同的长度%2.//昨天心情不大好特别想回家,一下午再看这道题晚上偷懒一直在看视频。。。//一开始觉得无非就是查看这个节点的深度,然后一直打算用h去计算,后不断地wa然后就想了想h是指该节点到最底下的那个高度,然后就开始用了另一个数组num去储存离跟节点的长度,也就是一 阅读全文
posted @ 2012-07-22 17:41 某某。 阅读(253) 评论(0) 推荐(0) 编辑