Heap Partition ZOJ - 3963(贪心)
贪心做一下就好了
反正别用memset
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <list>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff; struct node
{
int w, id;
node(int w, int id) : w(w), id(id) {}
};
bool operator < (node a, node b)
{
if(a.w == b.w) return a.id < b.id;
return a.w < b.w;
} set<node> s;
vector<int> G[maxn];
int b[maxn];
int ans[maxn]; int main()
{
int T;
rd(T);
while(T--)
{
s.clear();
int n;
rd(n);
int a, cnt = ;
for(int i = ; i <= n; i++) G[i].clear(), ans[i] = ;
set<node>::iterator it;
for(int i = ; i <= n; i++)
{
rd(a);
it = s.lower_bound(node(-a, -i));
if(it == s.end())
{
G[cnt].push_back(i);
b[i] = cnt++;
}
else
{
node x = *it;
G[b[-x.id]].push_back(i);
b[i] = b[-x.id];
if(++ans[-x.id] == )
s.erase(it);
}
s.insert(node(-a, -i)); }
pd(cnt);
for(int i = ; i < cnt; i++)
{
printf("%d", G[i].size());
for(int j = ; j < G[i].size(); j++)
{ printf(" %d", G[i][j]);
}
printf("\n");
} } return ;
}
Heap Partition ZOJ - 3963(贪心)的更多相关文章
- zoj 3963 Heap Partition(并查集,贪心,二分)
Heap Partition Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A sequence S = { ...
- ZOJ 3963 Heap Partition set维护。给一个序列,将其划分成尽量少的序列,使每一个序列满足按照顺序构造二叉树,父母的值<=孩子的值。
Heap Partition Time Limit: Seconds Memory Limit: KB Special Judge A sequence S = {s1, s2, ..., sn} i ...
- zoj-3963 Heap Partition(贪心+二分+树状数组)
题目链接: Heap Partition Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A sequence ...
- ZOJ 3963 Heap Partition(multiset + stl自带二分 + 贪心)题解
题意:给你n个数字s1~sn,要你把它们组成一棵棵二叉树,对这棵二叉树来说,所有节点来自S,并且父节点si<=子节点sj,并且i<j,问你树最少几棵二叉数.树 思路:贪心.我们往multi ...
- ZOJ 3963:Heap Partition(贪心+set+并查集)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3963 题意:给出一个n个数的序列,可以在其中找一个子序列建堆,并且堆中的父 ...
- zoj 3963 heap partion
https://vjudge.net/problem/ZOJ-3963 题意: 给出一个数列,可以用这个数列构造一种二叉树,这个二叉树满足数的下标 i <= j,并且 si <= sj,s ...
- 【贪心】【set】zoj3963 Heap Partition
贪心地从前往后扫,每到一个元素,就查看之前的元素中小于等于其的最大的元素是否存在,如果存在,就将它置为其父亲.如果一个结点已经是两个儿子的父亲了,就不能在set中存在了,就将他删除.如果然后将当前元素 ...
- ZOJ - 3715贪心
ZOJ - 3715KindergartenElection 题目大意:幼儿园里正在举办班长选举,除1号小朋友外每个人都会投他最好的朋友,但1号小朋友可以贿赂别人(小伙子有丶想法),被贿赂的小朋友就会 ...
- zoj 1375 贪心
https://vjudge.net/problem/ZOJ-1375 In modern day magic shows, passing through walls is very popular ...
随机推荐
- Redux进阶(Redux背后的Flux)
简介 Flux是一种搭建WEB客户端的应用架构,更像是一种模式而不是一个框架. 特点 单向数据流 与MVC的比较 1.传统的MVC如下所示(是一个双向数据流模型) 用户触发事件 View通知Contr ...
- 2019 Valentine's Day 圣地巡礼和WPR003N开箱刷U-boot记录
即兴打出这个标题,似乎性息量有点大,后面的内容真的和你想象的是一样的吗? 自上一篇blog告别这里有多少年了,掐指一算,今天是一个回归的日子,看着这里搭上云之路,渐渐的变成了云主机中的一员,感慨时事境 ...
- .net 笔试面试总结(2)
在.net 中类(class) 与结构(Struct)的异同. Class 可以被实例化,属于引用类型,是分配在内存的堆上的.类是引用传递的. Struct 属于值类型,是分配在内存的栈上的.结构体是 ...
- Web前端 web的学习之路2
2019 年 Web 开发技术指南和趋势 2019/01/23 · JavaScript · 趋势 转载:原文出处: 李棠辉(http://web.jobbole.com/95622/) 以下内 ...
- win10 64位IIS链接32位ACCESS数据库
window10中IIS运行.asp文件链接数据库时出现错误,显示“An error occurred on the server when processing the URL. Please co ...
- Odoo 10的Linux安装
CentOS7安装Odoo10流程如下一.更新系统#yum clean all#yum update 二.安装 PostgreSQL 1.安装数据库#yum install postgresql po ...
- 魅族5.0以上设备(亲测有效)激活Xposed框架的流程
对于喜欢研究手机的哥们来说,大多时候会使用到Xposed框架及种种功能强大的模块,对于5.0以下的系统版本,只要手机能获得ROOT权限,安装和激活Xposed框架是比较简单的,但随着系统版本的持续更新 ...
- 本地服务器硬件信息获取指令wmic
获取BIOS序列号 wmic bios list full | find "SerialNumber" SerialNumber=P50168VB 获取CPUID(WIN32_PR ...
- MongoDB 集合间关联查询后通过$filter进行筛选
在前面的分享中,有讲解 “详解MongoDB中的多表关联查询($lookup)” 一节,其内容涵盖了常见的集合管理的需求.我们知道文档的选择都是通过$match进行匹配刷选.但这是文档间的匹配筛选,并 ...
- 移动端click延迟和tap事件
一.click等事件在移动端的延迟 click事件在移动端和pc端均可以触发,但是在移动端有延迟现象. 1.背景 由于早期移动设备浏览网页时内容较小,为了增强用户体验,苹果公司专门为移动设备设计了双击 ...