zoukankan      html  css  js  c++  java
  • uva11991

    B - Easy Problem from Rujia Liu?

    题意:求v第k次出现的位置,如果出现次数少于k次,输出0.

    分析:预处理将一个值所有出现的位置放在一个数组中。

    代码:

    #include <map>
    #include <vector>
    #include <math.h>
    #include <string>
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    #define ll long long
    #define ull unsigned long long
    #define cls(x) memset(x,0,sizeof(x))
    #define clslow(x) memset(x,-1,sizeof(x))
    
    const int mod=1e9+7;
    const int maxn=1e5+100;
    
    int n,m,tot;
    
    int a[maxn];
    map<int,int>pos;
    
    struct Node{
        int val;
        vector<int>v;
    };
    Node node[maxn];
    
    int main()
    {
    //    freopen("in.txt","r",stdin);
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            tot=1;
            pos.clear();
            for(int i=1;i<=n;i++){
                scanf("%d",&a[i]);
                if(!pos[a[i]]){
                    node[tot].v.clear();
                    pos[a[i]]=tot;
                    node[tot].val=a[i];
                    node[tot++].v.push_back(i);
                }
                else{
                    node[pos[a[i]]].v.push_back(i);
                }
            }
    
            for(int i=1;i<=m;i++){
                int k,v,ans;
                scanf("%d%d",&k,&v);
                if(node[pos[v]].v.size()<k||pos[v]==0)   ans=0;
                else    ans=node[pos[v]].v[k-1];
                printf("%d
    ",ans);
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    CentOS 6.5通过yum的方式安装MySql
    Hbase集群搭建
    Thread类的常见问题
    关hashMap跟hashTable的区别
    mysql 循环插入100w
    Centos 多个mysql数据库
    CentOS 搭建 FastDFS-5.0.5集群
    RPC
    dubbo简述
    自己去看dubbo源码
  • 原文地址:https://www.cnblogs.com/shutdown113/p/9343372.html
Copyright © 2011-2022 走看看