• Atcoder---ID排序模拟结构体


    题目描述

    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≤Pi≤N
    ·1≤Yi≤109
    ·Yi are all different.
    ·All values in input are integers.

    输入

    Input is given from Standard Input in the following format:

    N M
    P1 Y1
    :
    PM YM

    输出

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

    样例输入

    2 3
    1 32
    2 63
    1 12
    

    样例输出

    000001000002
    000002000001
    000001000001
    
    #pragma GCC optimize (2)
    #pragma G++ optimize (2)
    #include <bits/stdc++.h>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    //#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll inf = 1e15;
    const int maxn = 2e6 + 7;
    const int mod = 1e9 + 7;
    int num[maxn],n,m;
    int father[maxn];
    int ans;
    /**struct node{
        int a,b;
    }cnt[maxn];
    bool cmp(node x,node y)
    {
        return ((x.b>y.b)||(x.b==y.b && x.a>y.a));
    }
    int findfather(int x){
        if(father[x]==x) return x;
        else return father[x]=findfather(father[x]);
    }**/
    struct node{
        int p,y,num;
    }cnt[maxn];
     
    int pnum[maxn],bnum[maxn];
    bool cmp(node a,node b){
        if(a.p==b.p) return a.y<b.y;
        return a.p<b.p;
    }
    int main()
    {
        /**int n=read;
        int cnt=0;
        for(int i=1;i<=n;i++) num[i]=read;
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
                if(i<j&&num[i]>num[j])
                    cnt++;
        }
        cout<<cnt;
        int n=read,m=read;
        for(int i=1;i<=m;i++)
        {
            cnt[i].a=read;
            cnt[i].b=read;
        }
        ll ans=0;
        sort(cnt+1,cnt+1+m,cmp);
        for(int i=1;i<=m;i++)
        {
            if(cnt[i].a>n) {
                ans+=n*cnt[i].b;
                break;
            }
            ans+=cnt[i].a*cnt[i].b;
            n-=cnt[i].a;
        }
        cout<<ans;
        n=read,m=read;
        for(int i=1;i<=n;i++) father[i]=i;
        for(int i=1;i<=m;i++)
        {
            int x=read,y=read;
            int judge1=findfather(x);
            int judge2=findfather(y);
            if(judge1!=judge2) father[judge2]=judge1;
        }
        for(int i=1;i<=n;i++){
            num[findfather(i)]++;
        }
        ans=0;
        for(int i=1;i<=n;i++)
        {
            if(ans<num[i]) ans=num[i];
        }
        cout<<ans;
        n=read,m=read;
        for(int i=0;i<m;i++)
        {
            p[i]=read,y[i]=read;
            cnt[p[i]].push_back(y[i]);
        }
        for(int i=0;i<n;i++) {
            sort(cnt[i+1].begin(),cnt[i+1].end());
        }
        for(int i=0;i<m;i++){
            printf("%012lld
    ",(ll)(p[i])*100000+(int)(lower_bound(cnt[p[i]].begin(),cnt[p[i]].end(),y[i])-cnt[p[i]].begin())+1);
        }**/
        n=read,m=read;
        for(int i=1;i<=m;i++)
        {
            cnt[i].p=read,cnt[i].y=read;
            cnt[i].num=i;
            pnum[i]=cnt[i].p;
        }
        sort(cnt+1,cnt+1+m,cmp);
        int tempx=cnt[1].p,tempcnt=1;
        for(int i=1;i<=m;i++)
        {
            if(tempx!=cnt[i].p){
                tempx=cnt[i].p;
                tempcnt=1;
            }
            bnum[cnt[i].num]=tempcnt++;
        }
        for(int i=1;i<=m;i++)
        {
            printf("%06d%06d
    ",pnum[i],bnum[i]);
        }
        return 0;
    }
    
  • 相关阅读:
    ECMAScript 引用类型Object 对象
    jQuery Form Plugin
    在 PHP5 中使用 DOM 控制 XML
    JavaScript encodeURI()和encodeURIComponent() 函数
    程序员进阶的建议:多看、多写、多交流
    jQuery 取 css zindex 值在各种浏览器中的返回值
    XPath 语法教程(Tutorial_2)
    使用 strpos 需要注意 === 运算符
    关于代码开发规范和原则
    PHP 编写大型网站问题集
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144206.html
Copyright © 2020-2023  润新知