zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 113 C

    C - ID


    Time limit : 2sec / Memory limit : 1024MB

    Score: 300 points

    Problem Statement

    In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

    City i is established in year Yi and belongs to Prefecture Pi.

    You can assume that there are no multiple cities that are established in the same year.

    It is decided to allocate a 12-digit ID number to each city.

    If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is Pi, and the last six digits of the ID number is x.

    Here, if Pi or x (or both) has less than six digits, zeros are added to the left until it has six digits.

    Find the ID numbers for all the cities.

    Note that there can be a prefecture with no cities.

    Constraints

    • 1≤N≤105
    • 1≤M≤105
    • 1≤PiN
    • 1≤Yi≤109
    • Yi are all different.
    • All values in input are integers.

    Input

    Input is given from Standard Input in the following format:

    N M
    P1 Y1
    :
    PM YM
    

    Output

    Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2).


    Sample Input 1

    Copy
    2 3
    1 32
    2 63
    1 12
    

    Sample Output 1

    Copy
    000001000002
    000002000001
    000001000001
    
    • As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.
    • As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.
    • As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.

    Sample Input 2

    Copy
    2 3
    2 55
    2 77
    2 99
    

    Sample Output 2

    Copy
    000002000001
    000002000002
    000002000003

    高级点的结构体排序,主要难点是判断每个区间的数字排序
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/stck:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    //#define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    #define ios() ios::sync_with_stdio(true)
    #define INF (1<<31)-1;
    #define mem(a) (memset(a,0,sizeof(a)))
    struct P{
        int x,y;
    }H[200000];
    vector<int>G[200000];
    int POS(int k,int value){
        int mid;
        int left = 0;
        int len = G[k].size();
        int right = len - 1;
        //cout<<" "<<k<<"A"<<value<<endl;
        while(left <= right){
     
            // 确保中点靠近区间的起点
            mid = left + (right-left)/2;
            //cout<<mid<<endl;
            //cout<<"mid= "<<mid<<" "<<left<<" "<<right<<endl;
            // 如果找到则返回
            if(G[k][mid] == value) return mid;
            // 将中点赋给终点
            else if(G[k][mid] > value) right = mid;
            // 将中点加一赋给起点
            else left = mid + 1;
        }
        return -1;
    }
    set<int>::iterator it;
    int main()
    {
        set<int>s;
        int N,M;
        int x,y;
        cin>>N>>M;
        for(int i=1;i<=M;i++){
            cin>>x>>y;
            H[i].x = x;
            H[i].y = y;
            G[x].push_back(y);
            s.insert(x);
        }
        for(int i=1;i<=N;i++){
            sort(G[i].begin(),G[i].end());
        }
     
     
        for(int i=1;i<=M;i++){
            cout<<setw(6)<<setfill('0')<<H[i].x;
            cout<<setw(6)<<setfill('0')<<POS(H[i].x,H[i].y)+1<<endl;
        }
        return 0;
    }


  • 相关阅读:
    实现一个可host asp.net程序的小型IIS(Cassinidev介绍)
    json数组对象和对象数组
    select 操作大全动态增中值
    jquery将某些ID显示出来
    如何合理利用好nofollow标签
    javascript读写COOKS
    [PHPNow] 使用PHPNOW常见的10个问题
    repeate 常用的每行显示几个共几行
    java学习之面向对象(this,static,pakage,import)
    Java学习之面向对象(1.Object类,(1)toString方法,(2)equals方法,2.对象转型(casting),3.动态绑定与多态,4.抽象类(abstract),5.Final关键字)
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/9906693.html
Copyright © 2011-2022 走看看