摘要: #pragma warning(disable:4786)#include #include #include #include #include #define zzzusing namespace std;int min(int a, int b){ return ab?a:b;}const int MAXN = 1000 + 5;int cnt;mapid;int ID(string s){ if(!id.count(s)) id[s]=cnt++; return id[s];}struct ZZ{ int p, q;};vectorzz[MAXN];int b, n;bool erfe 阅读全文
posted @ 2013-02-09 22:02 ChrisZZ 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 题意:给出一个a*b的网格,在网格上取不共线的三点构成三角形,求三角形总数。分析:就是一一道简单的组合数计算题目,设总结点数为n,则取三个节点的个数为C(n,3),然后减去横向、竖向、斜向的三点共线的个数即可,斜线三点共线等价于所枚举的矩形的长宽成倍数关系,即gcd不为1代码如下:#include #include using namespace std;long long gcd(long long a, long long b){ if(a%b==0) return b; return gcd(b, a%b);}int main(){ long long a, b; ... 阅读全文
posted @ 2013-02-09 08:19 ChrisZZ 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 题意:任取斐波那契数列中一项f[i],若对于所有j解法:这题的理论分析在黑书上有,结论是从第五项开始下标为素数的斐波那契数都是斐波那契素数#include #include const int MAXN = 250010;;int prime[25010];bool isprime[MAXN];long double fib[MAXN];int main(){ int i, j; for(i=0; i1e9){ fib[i]/=10; flag = true; } } int n; while(scanf("%d", &n)!=EOF) printf("% 阅读全文
posted @ 2013-02-09 08:17 ChrisZZ 阅读(192) 评论(0) 推荐(0) 编辑
摘要: DescriptionYou haveNintegers,A1,A2, ... ,AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval.InputThe first line contains two numbersNandQ. 1 ≤N,Q≤ 1000 阅读全文
posted @ 2013-02-09 08:15 ChrisZZ 阅读(359) 评论(0) 推荐(0) 编辑
摘要: DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营 地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工 兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时 向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开 始计算这一段的 阅读全文
posted @ 2013-02-09 08:13 ChrisZZ 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 题意:有一些简单化合物,每个化合物都由两种元素组成,每个元素用一个大写字母组成,你是一个装箱工人,从实验员那里按照顺序依次把一些简单化合物装到车上,但是这里存在一个安全隐患,如果车上存在k个简单化合物,正好包含k中元素,那么他们将组成一个易爆易燃的化合物,为了安全起见,每当你拿到一个化合物的时候,如果他和已装车的化合物形成易爆化合物,你就应当拒绝装车,否则就应该装车,编程输出有多少个没有装车的化合物。简单分析一下,从第一个化合物开始,如果第二个化合物组成元素与之完全相同,那么是易爆物,不能装车,应当拒绝;否则装车,再看第三个化合物...列举所有情况发现其实就是简单的并查集。代码如下:#incl 阅读全文
posted @ 2013-02-09 08:12 ChrisZZ 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 题意:有n个节点,初始时每个节点的父节点都不存在,你的任务是执行一次I操作和E操作,格式如下:I u v:把节点u的父节点设为v,距离为|u-v|除以1000的余数。输入保证之星指令前没有父节点E u:询问u到根节点的距离题意显然是要用并查集#include #include #include using namespace std;const int MAXN = 20000 + 10;int p[MAXN];int d[MAXN];int findset(int x){ if(p[x]!=x){ int root = findset(p[x]); d[x] += d[p[x]]; r... 阅读全文
posted @ 2013-02-09 08:12 ChrisZZ 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 题意很简单就不说了,见白书指导书P188这里就是学习一下priority的最简单的用法,自己写一个结构体,包含比较操作 operator #include #include using namespace std;structzz{ int n, p, t; bool operator z.t || (t==z.t && n>z.n); }};int main(){ priority_queuepq; char s[20]; zzz; while(scanf("%s", s) && s[0]!='#'){ scanf(& 阅读全文
posted @ 2013-02-09 08:10 ChrisZZ 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 给出一个包含n个整数的数组,每次询问两个整数k和v,输出从左到右第k个v的下标(从1到n)白书指导书的例题。。不过可以写的更短一点:#include #include #include #include using namespace std;map >a;int main(){ int n, m, x, y; while(scanf("%d%d", &n, &m) != EOF){ a.clear(); for(int i=0; i<n; i++){ scanf("%d", &x); a[x].push_back(i 阅读全文
posted @ 2013-02-09 08:09 ChrisZZ 阅读(145) 评论(0) 推荐(0) 编辑
摘要: Problem ?Dijkstra, Dijkstra.Time Limit: 10 secondsDexter:"You don't understand. I can't walk...they've tied my shoelaces together."Topper Harley:"A knot. Bastards!"Jim Abrahams and Pat Proft,"Hot Shots! Part Deux."You are a political prisoner in jail. Things 阅读全文
posted @ 2013-02-09 08:06 ChrisZZ 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 题目是网络流-最大流的模板题这里作为学习,把《指南》上Dinic的模板用了一下,代码如下:#include #include #include #include #include using namespace std;const int MAXN = 10000;const int INF = 0x3f3f3f3f;int min(int a, int b){ return a}struct Edge{ int from, to, cap, flow; Edge(int a, int b, int c, int d): from(a), to(b), cap(c), flo... 阅读全文
posted @ 2013-02-09 08:05 ChrisZZ 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 回文字符串时间限制:3000ms | 内存限制:65535KB难度:4描述所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba"。当然,我们给你的问题不会再简单到判断一个字符串是不是回文字符串。现在要求你,给你一个字符串,可在任意位置添加字符,最少再添加几个字符,可以使这个字符串成为回文字符串。输入第一行给出整数N(0接下来的N行,每行一个字符串,每个字符串长度不超过1000.输出每行输出所需添加的最少字符数样例输入1 Ab3bd样例输出2来源IOI 2000这题目只需要求个数,不必具体写出添加的字符,那么求原串和转置串的LCS的长度g,再用LE 阅读全文
posted @ 2013-02-09 08:03 ChrisZZ 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 子串和时间限制:5000ms | 内存限制:65535KB难度:3描述给定一整型数列{a1,a2...,an},找出连续非空子串{ax,ax+1,...,ay},使得该子序列的和最大,其中,1#include using namespace std;const int MAXN = 1000000 + 5;int dp[MAXN], a[MAXN];int main(){// freopen("in.txt", "r", stdin); int cas; scanf("%d", &cas); while(cas--){ int 阅读全文
posted @ 2013-02-09 08:02 ChrisZZ 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 单调递增子序列(二)时间限制:1000ms | 内存限制:65535KB难度:4描述给定一整型数列{a1,a2...,an}(0如:1 9 10 5 11 2 13的最长单调递增子序列是1 9 10 11 13,长度为5。输入有多组测试数据(#include #include using namespace std;const int MAXN = 100000 + 5;int main(){// freopen("in.txt", "r", stdin); int m, i, a[MAXN]; while(scanf("%d", & 阅读全文
posted @ 2013-02-09 08:01 ChrisZZ 阅读(179) 评论(0) 推荐(0) 编辑