[HDU]-6040 Hints of sd0061
来源:互联网 发布:磁盘碎片整理 知乎 编辑:程序博客网 时间:2024/06/05 00:56
http://acm.hdu.edu.cn/showproblem.php?pid=6040
std::nth_element
default (1) template < class RandomAccessIterator > void nth_element (RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);custom (2) template < class RandomAccessIterator, class Compare > void nth_element (RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
Sort element in range
Rearranges the elements in the range [first,last), in such a way that the element at the nth position is the element that would be in that position in a sorted sequence.
The other elements are left without any specific order, except that none of the elements preceding nth are greater than it, and none of the elements following it are less.
The elements are compared using operator< for the first version, and comp for the second.
nth_element 大法好,这个复杂度 o(n)
#include<stdio.h>#include<algorithm>using namespace std;const int MAXN = 10000009;int b[105], pos[105],n, m;unsigned a[MAXN], ans[105];unsigned x, y, z;inline unsigned rng61() { unsigned t; x ^= x << 16; x ^= x >> 5; x ^= x << 1; t = x; x = y; y = z; z = t ^ x ^ y; return z;}bool cmp(int X, int Y) { return b[X] < b[Y];}int main(){ for(int Case = 1; scanf("%d%d%u%u%u", &n, &m, &x, &y, &z) == 5; ++Case) { for(int i = 0; i < n; ++i) { a[i] = rng61(); } for(int i = 0; i < m; ++i) { scanf("%d", b + i); pos[i] = i; } sort(pos , pos + m, cmp); b[pos[m] = m] = n; a[n] = -1; for(int i = m - 1; i >= 0; --i) { nth_element(a, a + b[pos[i]], a + b[pos[i + 1]]); ans[pos[i]] = a[b[pos[i]]]; } printf("Case #%d:", Case); for(int i = 0; i < m; ++i) { printf(" %u", ans[i]); } putchar('\n'); } return 0;}
阅读全文
0 0
- HDU 6040 Hints of sd0061
- [HDU]-6040 Hints of sd0061
- HDU 6040 Hints of sd0061
- HDU-6040 Hints of sd0061
- hdu 6040 Hints of sd0061
- hdu 6040 Hints of sd0061
- Hints of sd0061 HDU
- HDU 6040 Hints of sd0061 STL
- hdu 6040 Hints of sd0061(STL)
- HDU 6040 Hints of sd0061 (技巧)
- hdu 6040 Hints of sd0061(nth_element)
- hdu 6040 Hints of sd0061(STL)
- HDU 6040 Hints of sd0061(nth_element)
- HDU 6040 Hints of sd0061 stl
- 【HDU 6040 Hints of sd0061】 思维 & STL
- HDU 6040 Hints of sd0061(快速排序)
- hdu 6040 Hints of sd0061[2017 Multi-University Training Contest
- hdu 6040 Hints of sd0061【STL线性排序函数】
- linux学习之旅(十一)&管理网络
- 欢迎使用CSDN-markdown编辑器
- c++分割字符串,strtok与strtok_r的使用记录
- C语言字符串函数的模拟实现(strlen、strcpy、strcat、strstr 、strcmp)
- cartographer源码分析(13)-transform-rigid_transform.h
- [HDU]-6040 Hints of sd0061
- 编写一个简单的内核模块
- 学习笔记2
- Android基于XMPP协议之实现即时通讯的原理
- Java 泛型的类型擦除和桥方法
- ArrayList VS LinkedList
- Node.js +Swagger Editor + Swagger-UI 环境搭建
- 线程池的使用和底层实现
- Unity学习笔记