• uva 11991 Easy Problem from Rujia Liu


    原题链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18696 
    方法很多,我用的是快排+二分,练习一下stl lower_bound这个函数。。。

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 using std::sort;
     7 using std::lower_bound;
     8 const int Max_N = 100010;
     9 struct node {
    10     int v, id;
    11 }rec[Max_N];
    12 int arr[Max_N];
    13 bool cmp(node &a, node &b) {
    14     if (a.v == b.v) return a.id < b.id;
    15     return a.v < b.v;
    16 }
    17 int main() {
    18 #ifdef LOCAL
    19     freopen("in.txt", "r", stdin);
    20     freopen("out.txt", "w+", stdout);
    21 #endif
    22     int n, m, a, b, pos;
    23     while (~scanf("%d %d", &n, &m)) {
    24         for (int i = 0; i < n; i++) {
    25             scanf("%d", &rec[i].v);
    26             rec[i].id = i + 1;
    27         }
    28         sort(rec, rec + n, cmp);
    29         for (int i = 0; i < n; i++) arr[i] = rec[i].v;
    30         while (m--) {
    31             scanf("%d %d", &a, &b);
    32             pos = lower_bound(arr, arr + n, b) - arr;
    33             node &k = rec[pos + a - 1];
    34             if (k.v == b) printf("%d
    ", k.id);
    35             else puts("0");
    36         }
    37     }
    38     return 0;
    39 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    Extension Methods(扩展方法)
    linux面试题
    渗透测试 day4
    渗透测试 day3
    渗透测试 day2
    渗透测试 day1
    9.3 网络安全介绍
    9.2 Iptables
    8.30 进程管理
    8.29 linux的网络
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4508143.html
Copyright © 2020-2023  润新知