解题报告:HDU_6040 Hints of sd0061 STL::nth_element
来源:互联网 发布:韩服数据 编辑:程序博客网 时间:2024/06/15 23:26
题目链接
题意:
给你一个序列的递推函数,m次询问,询问这个序列上第bi小的数。
官方题解:
最关键的部分在于了解STL里的nth_element函数,简单介绍一下:
这个函数的时间复杂度近似线性
函数的调用(取第n小):nth_element ( arr.begin() , arr+n,arr.end() )
调用函数后保证比第n个数小的数都在前面,比它大的数在后面
代码:
#include<bits/stdc++.h>using namespace std;int id[105],A[105];unsigned s[10000005];unsigned ans[105];int n,m;unsigned x,y,z;unsigned oper(){ 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 a,int b){ return A[a] < A[b];}int main(){ int cas = 0; while(scanf("%d%d%u%u%u",&n,&m,&x,&y,&z)==5){ for(int i=0;i<m;i++){ id[i] = i; scanf("%d",&A[i]); }A[m]=n;id[m]=m; for(int i=0;i<n;i++)s[i] = oper(); sort(id,id+m,cmp); for(int now,i=m-1,last=A[id[m]];i>=0;i--,last=now){ now = A[id[i]]; if(now==last){ ans[id[i]] = ans[id[i+1]]; }else { nth_element(s,s+now,s+last); ans[id[i]] = s[now]; } }printf("Case #%d:",++cas); for(int i=0;i<m;i++){ printf(" %u",ans[i]); }printf("\n"); }return 0;}
阅读全文
0 0
- 解题报告:HDU_6040 Hints of sd0061 STL::nth_element
- 【HDU6040】Hints of sd0061(nth_element)
- HDU 6040 Hints of sd0061(STL nth_element函数)
- hdu 6040 Hints of sd0061(nth_element)
- HDU 6040 Hints of sd0061(nth_element)
- hdu6040 Hints of sd0061【nth_element使用】
- 2017多校一 1008题 hdu 6040 Hints of sd0061 排序 STL nth_element
- HDU6040 Hints of sd0061【STL】
- HDU 6040 Hints of sd0061 STL
- HDU6040-Hints of sd0061(STL)
- hdu 6040 Hints of sd0061(STL)
- hdu 6040 Hints of sd0061(STL)
- HDU 6040 Hints of sd0061 stl
- 【HDU 6040 Hints of sd0061】 思维 & STL
- HDU6040-Hints of sd0061
- Hints of sd0061 HDU
- HDU 6040 Hints of sd0061 找第K大数 (nth_element函数)
- hdu 6040 Hints of sd0061【STL线性排序函数】
- 网络管理
- 深入解析ConcurrentHashMap的实现原理
- 安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置
- android,内部存储,外部存储,权限理解
- sso项目心得第一天
- 解题报告:HDU_6040 Hints of sd0061 STL::nth_element
- superDiamond例子
- Tools 命名空间的使用与 Support Library Annotations 介绍
- sql count(id)返回long型数据
- iOS11新特性,如何适配iOS11
- HDU6034 Balala Power!(思路+大数)
- android活动
- 剑指Offer:复杂链表的复制
- 一行数据自适应不换行