BZOJ4610——[Wf2016]Ceiling Functi
水题一道,不是很懂为啥没人做。。。
1、题意:纠正一下。。bzoj的题意不是很对。。。注意不是堆,是不平衡的二叉树,就是非旋转的treap,
另外。。。插入的时候,小于插在左边。。大于等于插在右边
2、分析:大概是wf签到题吧。。维护size,暴力的递归比较时候相同。。。。
<pre name="code" class="cpp">#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define M 10000
inline int read(){
char ch = getchar(); int x = 0, f = 1;
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while('0' <= ch && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
struct Node{
int size, x;
Node *ls, *rs;
} pos[M];
Node *root[M];
int tot;
int fa[M];
inline void insert(Node* &o, int x){
if(o == NULL){
o = &pos[++ tot];
o -> size = 1;
o -> x = x;
return;
}
o -> size ++;
if(x < o -> x) insert(o -> ls, x);
else insert(o -> rs, x);
}
inline int find(int x){
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
inline bool diff(Node *x, Node *y){
if(x == NULL && y == NULL) return 0;
if(x == NULL) return 1;
if(y == NULL) return 1;
if(x -> size != y -> size) return 1;
return diff(x -> ls, y -> ls) | diff(x -> rs, y -> rs);
}
int main(){
int n = read(), K = read();
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= K; j ++){
int x = read();
insert(root[i], x);
}
fa[i] = i;
}
for(int i = 1; i <= n; i ++){
for(int j = i + 1; j <= n; j ++){
if(!diff(root[i], root[j])){
int x = find(i), y = find(j);
if(x != y){
fa[x] = y;
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; i ++) if(find(i) == i){
ans ++;
}
printf("%d\n", ans);
return 0;
}
BZOJ4610——[Wf2016]Ceiling Functi的更多相关文章
- BZOJ 4610: [Wf2016]Ceiling Functi 水题
4610: [Wf2016]Ceiling Functi 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4610 Description ...
- bzoj 4610 Ceiling Functi
bzoj 4610 Ceiling Functi Description bzoj上的描述有问题 给出\(n\)个长度为\(k\)的数列,将每个数列构成一个二叉搜索树,问有多少颗形态不同的树. Inp ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- SQL Server 随机数,随机区间,随机抽取数据rand(),floor(),ceiling(),round(),newid()函数等
在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数.那就看下面 ...
- SQL中Round(),Floor(),Ceiling()函数的浅析
项目中的一个功能模块上用到了标量值函数,函数中又有ceiling()函数的用法,自己找了一些资料,对SQL中这几个函数做一个简单的记录,方便自己学习.有不足之处欢迎拍砖补充 1.round()函数遵循 ...
- freemarker中的round、floor和ceiling数字的舍入处理
freemarker中的round.floor和ceiling数字的舍入处理 1.简易说明 (1)round:四舍五入 (2)floor:向下取整 (3)ceiling:向上取整 2.举例说明 < ...
- SQL SERVER CEILING 函数 取整时的坑。。。
CEILING ---返回大于或等于指定数值表达式的最小整数 当舍去同一个大小的值 但是正负方向不一致时要注意小数位四舍五入的问题 例如: SELECT CEILING($123.45), CEI ...
- freemarker中的round、floor和ceiling数字的舍入处理(十七)
1.简易说明 (1)round:四舍五入 (2)floor:向下取整 (3)ceiling:向上取整 2.举例说明 <#--freemarker中的round.floor和ceiling数字的舍 ...
- 一:SqlServer中的 CEILING函数和 FLOOR函数以及ROUND()
例如 1.ROUND() 格式为ROUND(y1,y2,y3) y1:要被四舍五入的数字y2:保留的小数位数 y3:为0,可以不写,y1进行四舍五入,不为0则y1不进入四舍五入,如果y1有值就直接根据 ...
随机推荐
- VGA 视频输出
VGA Video Output by Nathan Ickes Introduction VGA is a high-resolution video standard used mostly fo ...
- Linux环境下发布项目(Tomcat重新启动)
在Linux系统下,重启Tomcat 首先,进入Tomcat下的bin目录 cd /usr/local/tomcat/bin 使用Tomcat关闭命令 ./shutdown.sh 查看Tomcat是否 ...
- 最短路径(Floyd)算法
#include <stdio.h>#include <stdlib.h>/* Floyd算法 */#define VNUM 5#define MV 65536int P[VN ...
- Lock的用法,为什么要用?
当多个进程分享数据的时候,对某段程序代码要lock(当对分享数据进行改写的时候). 我们先看些这段代码: namespace ThreadTest { class Program { static b ...
- Unicode 与 UTF 字符标准
Unicode 国际字符标准(UCS)是一个字符编码系统,它被设计用来支持世界各国不同语言书面文体之间的数据交换.处理以及显示. Unicode用两个字节表示一个字符.前127个字符与A ...
- sql 行转 列, 列转行
行列互转 复制代码 create table test(id ),quarter int,profile int) insert into test values(,,) insert into te ...
- javascript Date format(js日期格式化)
这个用这比较爽,记录一下// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年( ...
- cpg数据库处理_找到未提取的pdf
cpg数据库处理_找到未提取的pdf,存放于文件夹Chinese_undeal_pdfs move_unextracted_pdfs.py # -*- coding: utf-8 -*- " ...
- VIM的姿势
http://blog.csdn.net/vincent_czz/article/details/7900670 http://bbs.feng.com/read-htm-tid-7435912.ht ...
- JQuery中serialize()、serializeArray()和param()方法示例介绍
在项目中做form表单提交的时候,如果参数比较少,可以通过jquery一个个取得,但是当 form表参数很多的情况下,还是一一取得的话无疑是加大了工作量,那我们需要咱们获取到表单的所有参数呢,幸好,j ...