1. 程式人生 > >UVA 11991 Easy Problem from Rujia Liu? 簡單STL

UVA 11991 Easy Problem from Rujia Liu? 簡單STL

pri i++ mes 技術 can 思考 交集 namespace sin

  題目鏈接: UVA, 你懂的

  題目描述: 給出一串數, 求第幾次出現的數字幾?

  解題思路: 北交集訓STL水題

  代碼:

技術分享
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

const int MAXN = 1e5 + 7;
map<int, int> cnt;
map<pair<int, int>, int> M;
int arr[MAXN];

int main() {
    
int n, m; while( scanf( "%d%d", &n, &m ) != EOF ) { cnt.clear(); M.clear(); memset(arr, 0, sizeof(arr)); for( int i = 1; i <= n; i++ ) { scanf( "%d", &arr[i]); if( cnt.count(arr[i]) == 0 ) { cnt.insert(make_pair(arr[i],
1)); M.insert(make_pair(make_pair(1, arr[i]), i)); } else { cnt[arr[i]]++; M.insert(make_pair(make_pair(cnt[arr[i]], arr[i]), i)); } } for( int i = 1; i <= m; i++ ) { int times, num; scanf(
"%d%d", &times, &num ); printf( "%d\n", M[make_pair(times, num)]); } } return 0; }
View Code

  思考: 沒啥的, 繼續補題吧

UVA 11991 Easy Problem from Rujia Liu? 簡單STL