zoj 3862 Intersection(枚举)
来源:互联网 发布:淘宝密码怎么修改 编辑:程序博客网 时间:2024/04/30 02:01
Edward has 2n points on the plane conveniently labeled with 1,2,…,2n. Each point is connected exactly with another point by a segment.
Edward finds that some segments intersecting with some others. So he wants to eliminate those intersections with the following operation: choose two points i and j (1 ≤ i, j ≤ 2n) and swap their coordinates.
For example, Edward has 4 points (0, 0), (0, 1), (1, 1), (1, 0). Point 1 is connected with point 3 and point 2 is connected with 4. Edward can choose to swap the coordinates of point 2 and point 3.
Edward wants to know whether it is possible to use at most n + 10 operations to achieve his goal.
No two points coincide and no three points are on the same line.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains an integer n (1 ≤ n ≤ 100000).
Each of the following 2n lines contains 2 integers xi, yi which denotes the point (xi, yi). (|xi|, |yi| ≤ 109).
Each of the following n lines contains 2 integers ai, bi (1 ≤ ai, bi ≤ 2n, ai ≠ bi), which means point ai and point bi are connected by a segment.
The sum of values n for all the test cases does not exceed 300000.
Output
For each test case, print a line containing an integer m, indicating the number of operations needed. You must assure that m is no larger than n + 10. If you cannot find such a solution, just output "-1" and ignore the following output.
In the next m lines, each contains two integers i and j (1 ≤ i, j ≤ 2n), indicating an operation, separated by one space.
If there are multiple solutions, any of them is accepted.
Sample Input
120 00 11 11 01 32 4
Sample Output
12 3
使得这些点之间没有交叉 求最小的调节数 输出相应调节的点
由于题目中并没有要求 求出最小的调节数 所以我们可以通过枚举的方法
首先按照x坐标小y坐标小在前 进行排序 记录点在排序之前 排序之后的顺序
然后从左下角开始枚举点 如果它对面的点不是应该连接的那个点 那么就要交换点的位置
然后 经过调节 使得所有的线段都是平行的
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 200010#define MAXM 100010#define INF 99999999#define ll __int64#define bug cout<<"here"<<endl#define fread freopen("ceshi.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;int Read(){ char ch; int a = 0; while((ch = getchar()) == ' ' | ch == '\n'); a += ch - '0'; while((ch = getchar()) != ' ' && ch != '\n') { a *= 10; a += ch - '0'; } return a;}void Print(int a) //输出外挂{ if(a>9) Print(a/10); putchar(a%10+'0');}struct node{ int x,y,id; bool operator<(const node &p)const { if(y==p.y) return x>p.x; return y>p.y; }}no[MAXN];int link[MAXN];//link[i]代表i连接的点int now[MAXN];//排序之前 所在的位置int p[MAXN];//排序之后所在的位置int ans[MAXN+10][2];int main(){// fread; int tc; scanf("%d",&tc); while(tc--) { int n; scanf("%d",&n); for(int i=1;i<=2*n;i++) { scanf("%d%d",&no[i].x,&no[i].y); no[i].id=i; } for(int i=1;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); link[x]=y; link[y]=x; } sort(no+1,no+2*n+1); for(int i=1;i<=n*2;i++) { now[i]=no[i].id; p[no[i].id]=i; } int num=0; for(int i=1;i<=n;i++) { int s=2*i-1,t=2*i; if(link[now[s]]==now[t]) continue; else { ans[num][0]=now[t]; ans[num][1]=link[now[s]]; num++; p[now[t]]=p[link[now[s]]]; now[p[link[now[s]]]]=now[t]; p[link[now[s]]]=t; } } printf("%d\n",num); for(int i=0;i<num;i++) { printf("%d %d\n",ans[i][0],ans[i][1]); } } return 0;}
- zoj 3862 Intersection(枚举)
- ZOJ 3862 Intersection
- ZOJ 3862 Intersection (dijkstra)
- ZOJ-3862-Intersection【贪心】
- zoj 3862 Intersection (技巧题)
- ZOJ 3862 Intersection【贪心】【几何】【模拟】
- zoj 1403 Safecracker(枚举)
- ZOJ-2274(最大公约数 + 枚举)
- ZOJ 3710 Friends(枚举)
- ZOJ 3987 Numbers(枚举)
- ZOJ 1199 Point of Intersection
- zoj 1199 Point of Intersection
- ZOJ 1199Point of Intersection
- ZOJ 1409 Communication System(枚举 + 贪心)
- ZOJ 3715 Kindergarten Election(枚举+贪心)
- zoj H Kindergarten Election (枚举+贪心)
- ZOJ 3715 Kindergarten Election(枚举+贪心)
- ZOJ-3715 Kindergarten Election(贪心+枚举)
- 在手机上配置Android开发调试环境
- Windows7下安装Oracle 10g提示“程序异常终止,发生未知错误”的解决方法
- ARM内核全解析,从ARM7,ARM9到Cortex-A7,A8,A9,A12,A15到Cortex-A53,A57
- 机器学习入门的书单(数据挖掘、模式识别等一样)
- 马赫带现象
- zoj 3862 Intersection(枚举)
- 超实用的JavaScript技巧及最佳实践(下)
- 198 House Robber
- http知识点
- 如何在eclipse cdt环境下 导入一个含makefile的工程文件
- Mybatis的几点小结
- iOS中block介绍(三)揭开神秘面纱(上)
- 数据结构关于AOV与AOE网的区别
- 感受亮度与光强,及马赫带效应