ZCMU Problem A: Good Joke!

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;
}

  

时间: 2024-07-30 21:33:36

ZCMU Problem A: Good Joke!的相关文章

ZCMU Problem H: Crixalis&#39;s Equipment(贪心,排序)

#include<stdio.h> #include<stdlib.h> struct node { int a,b; }c[1002]; int cmpxy(const struct node *c,const struct node *d) { return (d->b - d->a) - (c->b - c->a); } int main() { int n,i,v,t,flag; // freopen("a.txt","

HNU Joke with permutation (深搜dfs)

题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=13341&courseid=0 Joke with permutation Time Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KB Total submit users: 85, Accepted users: 57 Problem 13341 : Special judge Prob

CF GYM 100548 Built with Qinghuai and Ari Factor(2014ACM西安现场赛Problem A)

ProblemA. Built with Qinghuai and Ari Factor Description DISCLAIMER: Allnames, incidents, characters and places appearing in this problem arefictitious. Any resemblance to actual events or locales or realpersons, living or dead, is purely coincidenta

hdu 4946 Just a Joke(数学+物理)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4969 Just a Joke Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 332    Accepted Submission(s): 135 Problem Description Here is just a joke, and do

Codeforces Amusing Joke 题解

So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name i

ZCMU 1894: Power Eggs

http://acm.zcmu.edu.cn/JudgeOnline/problem.php?id=1894 题意: 有M个鹰蛋,N层楼,鹰蛋的硬度是E,也就是说在1~E层楼扔下去不会碎,E+1层楼扔下去会碎. 给定M,N,问最坏情况下至少几次能得到E的具体的值.(E可能为0) ①n<=100. ②n<=1000. ③n<=100000. ④n<=1000000. ⑤n<=1000000000. 推荐学习资料: 朱晨光IOI2004集训队论文 从<鹰蛋>一题浅析对

2018 Multi-University Training Contest 4 Problem J. Let Sudoku Rotate 【DFS+剪枝+矩阵旋转】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6341 Problem J. Let Sudoku Rotate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1363    Accepted Submission(s): 717 Problem Description Sudoku i

A Math Problem

A Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 237    Accepted Submission(s): 117 Problem Description You are given a positive integer n, please count how many positive integers

Water Problem

water problem 发布时间: 2015年10月10日 15:34   时间限制: 1000ms   内存限制: 256M 描述 题意很简单 给你N个数, Q个查询 每次查询给你一个区间[L, R] 你要找出 [L, R] 这个区间里面取模M后的最大值. 输入 第一行一个T,表示测试数据组数.第二行两个整数N, M (1<=N<=10^5, 1<=M<=10^9).第三行给你N个整数 整数范围在1到10^9之间.第四行给你一个整数Q. ( 1<=Q<=10^5)