Problem A: Good Joke!

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 25  Solved: 16
[Submit][Status][Web Board]

Description

Vadim and Roman like discussing challenging problems with each other. One day Vadim told his friend following problem:

Given N points on a plane. Each point p is defined by it's two integer coordinates — px and py. The distance between points a and b is min(|ax - bx|, |ay - by|). You should choose a starting point and make a route visiting every point exactly once, i.e. if we write down numbers of points in order you visit them we should obtain a permutation. Of course, overall distance walked should be as small as possible. The number of points may be up to 40.

"40? Maybe 20? Are you kidding?" – asked Roman. "No, it's not a joke" – replied Vadim. So Roman had nothing to do, but try to solve this problem. Since Roman is really weak in problem solving and you are the only friend, except Vadim, with whom Roman can discuss challenging tasks, he has nobody else to ask for help, but you!

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.The first line of each test case contains a single integer N denoting the number of points on a plane. The following N lines contain two space-separated integers each — coordinates of points.

Constraints

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 40
  • 0 ≤ absolute value of each coordinate ≤ 1000
  • 1 ≤ sum over all N in a single test file ≤ 120

Output

Output the answer for every test case in a separate line. The answer for every test case is a permutation of length N. In case there are several solutions that lead to minimal distance walked, you should choose the lexicographically smallest one. Let P denote such permutation. To make output smaller, you should output H(P)H(P) = P1 xor P2 xor ... xor PN. Have a look at the example and it's explanation for better understanding.

Sample Input

2
2
1 2
0 0
3
3
3
0 0
0 3

Sample Output

3
0

HINT

天坑。

#include<stdio.h>
main()
{
int t,n; scanf("%d",&t);
while(t--)
{
int ans=0,i;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
ans^=i;
}
printf("%d\n",ans);
}
return 0;
}

  

最新文章

  1. Redis集群(三):主从配置一
  2. Recall, Precision and F-score
  3. Maven 入门 (1)—— 安装
  4. 3.saltstack的grains和pillar学习笔记
  5. JS 之BOM
  6. java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState解决?
  7. Linux下Find命令的使用
  8. ACM2033
  9. 李洪强iOS开发之-环信02.1_环信 SDK 2.x到3.0升级文档
  10. 转--浅谈ETL
  11. Beego学习笔记——开始
  12. NodeJS初介
  13. 还不知道spring的RestTemplate的妙用吗
  14. ROS学习备忘
  15. luogu1983 车站分级 (拓扑排序)
  16. 11、python阶段测试
  17. ElasicSearch(2) Linux运行
  18. php &amp;符的写法
  19. ACtiveMQ中间件-消息的接收和发送
  20. fms +fme 视频直播

热门文章

  1. 更换Sublime Text主题字体
  2. [bzoj3004] [SDOi2012]吊灯
  3. [BZOJ3473][BZOJ3277]字符串
  4. [Leetcode] Wildcard matching 通配符匹配
  5. Backup and Restore MySQL Database using mysqlhotcopy
  6. bzoj 2566 calc 拉格朗日插值
  7. PHP正则匹配与替换的简单例子
  8. 根据select创建input并赋值
  9. 常见通用的 JOIN 查询
  10. express添加拦截器