===数据结构===
yhf_2015
无。。。
展开
-
【bzoj 1798】[AHOI2009]维护序列
题目描述老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成。 有长为N的数列,不妨设为a1,a2,…,aN 。有如下三种操作形式: (1)把数列中的一段数全部乘一个值; (2)把数列中的一段数全部加一个值; (3)询问数列中的一段数的和,由于答案可能很大,你只需输出这个数模P的值。输入输出格式输入格式:第一行两个整数N和P(1≤P≤1000000000)。第二行含有N原创 2016-08-21 02:07:45 · 608 阅读 · 1 评论 -
【BZOJ 1251】序列终结者
Splay的序列操作 注意: 更新的时候,要先确定子树不为空在进行更新。 空指针的mx值要设为-inf#include #include #include using namespace std;const int maxn = 50010;struct node{ int num, val, size, turn, mx, add; node *pre, *c原创 2017-02-05 21:07:57 · 243 阅读 · 0 评论 -
【BZOJ 1047】理想的正方形
题目来源:BZOJ 1047思路:用二维单调队列维护二维数组的最大值和最小值,之后直接查询。 具体的来说,先用单调队列维护每一行的值,再维护每一列的值。代码:#include <cstdio>#include <iostream>#include <algorithm>using namespace std;inline int gt(){ char c = ' '; in原创 2016-12-10 14:00:27 · 289 阅读 · 0 评论 -
【洛谷 1160】 队列安排
思路双端队列,开指针数组记录位置,简单模拟。代码#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;struct node{ int num; node *pre, *nxt;};node lis[100010];node *pos[原创 2016-10-27 16:20:18 · 300 阅读 · 0 评论 -
【洛谷 1449】 后缀表达式
思路用栈来模拟操作,遇到符号就取栈顶的两个元素,进行操作。代码#include <cstdio>#include <iostream>#include <cstring>using namespace std;char ch[2010];int stack[2010], p;int main(){ scanf("%s", ch+1); int len = strlen(c原创 2016-10-27 14:36:55 · 538 阅读 · 0 评论 -
【poj 2524】Ubiquitous Religions
题意:有n个学生,m个关系,每个关系a b,以为a b的宗教相同,问最多有多少种宗教。思路:用并查集维护学生的宗教集合,最后遍历统计答案。代码:#include <cstdio>#include <iostream>using namespace std;int fa[50010], cnt, t;bool vis[50010];int find(int x){ return fa原创 2016-10-18 12:56:28 · 216 阅读 · 0 评论 -
【poj 3250】 Bad Hair Day
单调栈#include #include using namespace std;long long n, a1[80010], p1[80010], p, ans;int main(){ scanf("%lld", &n); for(int i = 1; i <= n; i ++) scanf("%lld", &a1[i]); a1[++n] = 1e9+10; f原创 2016-09-29 11:20:20 · 277 阅读 · 0 评论 -
【vijos 1659】 河蟹王国
线段树裸题。注意:更新的操作一定要在修改之后再进行,否则最大值变小后无法更新。#include using namespace std;#define mid ((l+r)>>1)#define lch (now<<1)#define rch ((now<<1)+1)#define fa (now>>1)const int maxn = 100010;typedef原创 2016-09-21 21:24:55 · 329 阅读 · 0 评论 -
【洛谷 2839】 畅通工程
并查集基础题,适合初学者练习。#include using namespace std;int fa[1010], ans;bool vis[1010];int find(int x){ return fa[x] == x ? x : fa[x] = find(fa[x]);}int main(){ int n, m; scanf("%d%d", &n, &m);原创 2016-09-21 15:08:25 · 253 阅读 · 0 评论 -
【洛谷 1054】[NOIP2005] 等价表达式
描述明明进了中学之后,学到了代数表达式。有一天,他碰到一个很麻烦的选择题。这个题目的题干中首先给出了一个代数表达式,然后列出了若干选项,每个选项也是一个代数表达式,题目的要求是判断选项中哪些代数表达式是和题干中的表达式等价的。这个题目手算很麻烦,因为明明对计算机编程很感兴趣,所以他想是不是可以用计算机来解决这个问题。假设你是明明,能完成这个任务吗?这个选择题中的每个表达式都满足下面原创 2016-08-25 16:31:19 · 1214 阅读 · 0 评论 -
【洛谷 2024】[NOI2001]食物链
题目描述动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形。A 吃 B,B吃 C,C 吃 A。现有 N 个动物,以 1 - N 编号。每个动物都是 A,B,C 中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这 N 个动物所构成的食物链关系进行描述:第一种说法是“1 X Y”,表示 X 和 Y 是同类。第二种说法是“2 X Y”,表示 X 吃原创 2016-08-25 19:30:33 · 645 阅读 · 0 评论 -
【洛谷 1168】中位数
题目描述给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[2], …, A[2k - 1]的中位数。[color=red]即[/color]前1,3,5,……个数的中位数。输入输出格式输入格式:输入文件median.in的第1行为一个正整数N,表示了序列长度。第2行包含N个非负整数A[i] (A[i] ≤ 10^9)原创 2016-08-25 16:12:41 · 833 阅读 · 0 评论 -
【BZOJ 2325】[ZJOI2011]道馆之战
思路:代码:#include #include #include #include using namespace std;const int maxn = 30010;int n, m;int head[maxn], to[maxn1], nxt[maxn1], cnt;int top[maxn], dep[maxn], son[maxn], sz[maxn],原创 2017-04-20 08:17:34 · 184 阅读 · 0 评论