ZOJ 3963 Heap Partition(贪心)
来源:互联网 发布:二维码生成软件设备 编辑:程序博客网 时间:2024/06/06 01:28
A sequence
Chiaki has a sequence
Note that a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
序列
现在有一个序列
解题思路
已知每个树上的节点 set
来维护,保证其根据点对应的 set.upper_bound()
可以在
需要注意的是,每个节点最多只能有两个子节点,故当某节点已经连接了两个子节点后,应将其从 set
中删除。
代码
#include<bits/stdc++.h>using namespace std;const int N = 100000 + 10;vector<int> v[N];int n, a[N], cnt, dig[N];struct Node { int first, second;} p;bool operator<(Node x, Node y){ if(a[x.second] == a[y.second]) return x.second < y.second; return a[x.second] < a[y.second];}set<Node > st;set<Node >::iterator it;int main(){ int T; scanf("%d",&T); while(T--) { st.clear(); cnt = 0; scanf("%d",&n); memset(dig, 0, 4*n+4); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); p.second = i; it = st.upper_bound(p); if(it==st.begin()) { v[cnt].push_back(i); p.first = cnt, p.second = i; st.insert(p); cnt++; } else { it--; p = *it; dig[p.second]++; if(dig[p.second] == 2) st.erase(it); p.second = i; st.insert(p); v[p.first].push_back(i); } } printf("%d\n", cnt); for(int i=0;i<cnt;i++) { printf("%d", v[i].size()); for(int j=0;j<v[i].size();j++) printf(" %d", v[i][j]); printf("\n"); v[i].clear(); } }}
- ZOJ 3963 Heap Partition(贪心)
- ZOJ 3963 Heap Partition(贪心)
- ZOJ-3963-Heap Partition(贪心)(STL)
- ZOJ 3963 Heap Partition( 并查集 + 贪心 +二分 )
- zoj 3963 Heap Partition 贪心+upper_bound()
- 浙江14届省赛 F.Heap Partition(ZOJ 3963)[贪心][二分]
- ZOJ 3963 Heap Partition (STL)
- ZOJ 3963 STL + 贪心
- ZOJ 2343(贪心)
- ZOJ 3715 (贪心)
- zoj-3721(贪心)
- ZOJ3963 Heap Partition
- ZOJ3963-Heap Partition
- ZOJ _3607_Lazier Salesgirl(贪心)
- ZOJ 2921 Stock(贪心)
- zoj 2921 Stock(贪心)
- ZOJ 1877 Bridge(贪心)
- ZOJ 3953 Intervals (贪心)
- MyBatis-学习笔记-1
- 百度云应用基础版数据库连接
- R语言进行中文分词和聚类
- 取消后续事件
- LeetCoder 2. Add Two Numbers
- ZOJ 3963 Heap Partition(贪心)
- 题目1366:栈的压入、弹出序列
- php系统函数
- CSS三类写法
- 欢迎使用CSDN-markdown编辑器
- 模拟计算机计算源码、反码、补码(难度系数:1颗星)
- ZOJ 3960 What Kind of Friends Are You?(哈希)
- SpringBoot实战 之 入门篇
- 【笔记】formvalidtor中的ajaxValidator用法