22 篇文章 0 订阅
2 篇文章 0 订阅
5 篇文章 0 订阅

# 题目链接

http://icpc.moe/onlinejudge/showProblem.do?problemId=5474

# AC代码

#include <iostream>
#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

struct node_t
{
int x, y;
int id;
int to;
bool friend operator < (node_t a, node_t b)
{
if (a.x == b.x)return a.y>b.y;
return a.x < b.x;
}
}
node[200000 + 100];

int pos[200000 + 100];
pair<int, int>ans[200000 + 200];
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
int cnt_ans = 0;
memset(pos, 0, sizeof pos);
int n;
scanf("%d", &n);
for (int i = 1; i <= 2 * n; ++i)
{
int x, y;
scanf("%d%d", &x, &y);
node[i].x = x;
node[i].y = y;
node[i].id = i;
}
for (int i = 1; i <= n; ++i)
{
int a, b;
scanf("%d%d", &a, &b);
node[a].to = b;
node[b].to = a;
}
sort(node + 1, node + 1 + 2 * n);
for (int i = 1; i <= 2 * n; ++i)
{
pos[node[i].id] = i;
}
for (int i = 1; i < 2 * n; i += 2)
{
if (node[i].to == node[i + 1].id && node[i + 1].to == node[i].id);
else
{
ans[cnt_ans++] = make_pair(node[i].id, node[pos[node[i + 1].to]].id);
int id1 = node[i].id, id2 = node[i + 1].to;
int pos2 = pos[id2];
swap(node[i].id, node[pos2].id);
swap(node[i].to, node[pos2].to);
pos[id1] = pos2;
pos[id2] = i;
}
}
printf("%d\n", cnt_ans);
for (int i = 0; i < cnt_ans; ++i)
{
printf("%d %d\n", ans[i].first, ans[i].second);
}
}
return 0;
}
• 1
点赞
• 0
收藏
• 打赏
• 0
评论
04-27 50
08-18 1424
04-02 1万+
09-15 196
07-05 326
08-23 1525
05-15 6436
05-16 1454
05-16 121
07-26 710
01-27 1205
08-15 623
10-14 809
08-01 322
03-16 718

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

The_Dawn_Star

¥2 ¥4 ¥6 ¥10 ¥20

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