A - Present Problem UVALive - 7000

这个题目一开始是想着交换的思路,就是一能去二,二也能去一,就是交换的顺序注意一下就可以,其实就是反着推一遍就可以,记得顺序要是反的,从最后推到前面。记得可能有重复的点,这个题目,

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 10;
struct Node
{
    int x,y;
    Node(int a = 0,int b = 0)
    {
        x = a;
        y = b;
    }
    //operator
} num[maxn];
int n,m,l;
int par[maxn];
int ans[maxn];
bool judge(Node a,Node b)
{
    if(a.x == b.x && a.y == b.y)
        return true;
    return false;
}
void init()
{
    for(int i = 0; i < n; i++)
    {
        par[i] = i;
    }
}
bool cmp(const Node a,const Node b)
{
    if(a.y != b.y)
        return a.y < b.y;
    return a.x < b.x;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        //memset(ans,0,sizeof(ans));
        scanf("%d %d %d",&n,&m,&l);
        init();
        for(int i = 0; i < m; i++)
        {
            int x,y;

            scanf("%d %d",&num[i].x,&num[i].y);    
        }
        sort(num,num+m,cmp);
        for(int i = 0; i < m; i++)
        {
            int l = num[i].x;
            int r = l+1;
            if(r >= n)
                continue;
            if(i != m - 1 && judge(num[i],num[i+1]))
                continue;
            swap(par[l],par[r]);
        }
        for(int i = 0; i < n; i++)
        {
            ans[par[i]] = i;
        }
        for(int i = 0; i < n; i++)
        {
            cout<<ans[i]<<endl;
        }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值