IT民工
加油!
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 29 下一页
摘要: 这道题是求字符串最小表示的第一个字符在字符串中的位置。做之前看了IOI2003冬令营周源大神的论文《浅析“最小表示法”思想在字符串循环同构问题中的应用》。这里虽然每个样例只有一个字符串,但是我们可以构造出一个字符串s+1,和s来找同构,然后取找到的位置i,j之中小的那个。/*Accepted 100K 16MS C++ 700B 2012-08-03 09:39:45*/#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace s 阅读全文
posted @ 2012-08-03 09:45 找回失去的 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 按照字符串的逆序排序。/*Accepted 100K 16MS C++ 863B 2012-08-03 08:30:48*/#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;const int MAXN = 55, MAXM = 110;struct str{ char s[MAXN]; int r;}t[MAXM];int n, m;bool cmp(str a, str b){ return a.r < 阅读全文
posted @ 2012-08-03 08:38 找回失去的 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 排序后输出中位数,直接用algorithm的sort。/*Accepted 204K 32MS C++ 347B 2012-08-02 17:13:37*/#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int MAXN = 10010;int a[MAXN], n;int main(){ int i; while(scanf("%d", &n) == 1) { for(i = 0; i < n; i ++) .. 阅读全文
posted @ 2012-08-02 17:16 找回失去的 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 题意描述的是求冒泡排序过程中交换的次数。如果用冒泡排序统计次数的话会超时,因为有这么一条性质,排序交换的次数等于逆序数之和,所以转化成求逆序数之和。用归并排序。#include<stdio.h>#include<string.h>#include<stdlib.h>const int MAXN = 500050;int A[MAXN], T[MAXN], n;__int64 cnt;void MergeSort(int l, int r){ int p, q, i, m; if(r - l > 1) { m = l + r >> 1; p 阅读全文
posted @ 2012-08-02 17:07 找回失去的 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 建立字典树,树的结点记录根结点到该结点的连续异或值。由(a^c)^(b^c)==a^b可得任意两结点的异或值,等于两结点之间这条路的连续异或值。由此把每个结点的值插入01字典树,从二进制31位~0位,并查找,尽可能的向每一位的不同方向查找(这样异或这一位能得1),取最大值。位运算还得继续学习。/*Accepted 44068K 875MS C++ 1756B 2012-08-02 16:10:05*/#include<stdio.h>#include<string.h>#include<stdlib.h>const int MAXN = 210000;typ 阅读全文
posted @ 2012-08-02 16:26 找回失去的 阅读(507) 评论(0) 推荐(0) 编辑
摘要: 和1056一样是判断前缀,唯一的区别就是这里是个10叉树。/*Accepted 2776K 110MS C++ 961B 2012-08-02 14:06:58*/#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct{ int next[10]; int alr, end;}Trie;Trie t[110000];int tp, n;int insert(char *x, int site){ if(t[site].end) return 1; ... 阅读全文
posted @ 2012-08-02 14:12 找回失去的 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 判断编码是否合法。合法的编码不允许出现一个编码是另一个编码的前缀。问题就在判断是否出现这样的情况。用字典树存储,定义两个标记,end为0代表当前结点是一个编码的结束,alr为1代表有一个编码经过了这个结点。由字典树的性质,当一个编码结束的结点alr为1,那么代表这个编码是另一个编码的前缀。此外,当一个编码经过的某个结点出现end值为1的情况,说明有一个编码是当前编码的前缀。/*Accepted 168K 0MS C++ 1044B 2012-08-02 13:05:53*/#include<stdio.h>#include<string.h>#include<.. 阅读全文
posted @ 2012-08-02 13:16 找回失去的 阅读(1353) 评论(0) 推荐(0) 编辑
摘要: 字典树存储,用并查集判连通,欧拉回路判通路。/*Accepted 59208K 422MS C++ 1191B 2012-08-02 11:38:21*/#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct{ int next[26]; int cnt, ord;}Trie;Trie t[3000000];int tp, op;int p[510000];char s1[20], s2[20], odd;int find(int x){ return p[x] ==... 阅读全文
posted @ 2012-08-02 11:43 找回失去的 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 这是去年北京赛区的B题,给出n个点,用这些点构造三角形,然后找出相似三角形个数的最大值。昨天看这题的时候以为很难,后面发现n的范围也就18,18^3也不大,可以直接暴力做。构造三角形的时候要注意两点:(1)这道题会有重点,需要判重。判重时可以将点平移,然后用一个200*200的数组做标记就行了。(2)判断三点共线,只需求出第一个与第三个点、第二个点与第三个点连线的斜率,斜率相等必然共线。此外,处理的时候将a作为最小边、b作为中边、c作为最长边。方便判断相似。/*Accepted 4082 0MS 416K 2343 B G++ Yu*/#include<st... 阅读全文
posted @ 2012-08-02 09:56 找回失去的 阅读(441) 评论(0) 推荐(0) 编辑
摘要: 求哈夫曼树的平均码长,用优先队列来写,先记录某个字符在字符串里出现的次数,然后放入队列。依次取出第一小和第二小的数,将两个数相加,构成新的虚拟结点,放入队列中。/*Accepted 196K 0MS C++ 918B 2012-08-01 17:25:00*/#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>using namespace std;int key[1 << 7], len;char t[1 << 10];int huffm 阅读全文
posted @ 2012-08-01 17:33 找回失去的 阅读(248) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 29 下一页