题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1391
Orz odd
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 23(10 users) Total Accepted: 9(8 users) Rating: Special Judge: No
Description
An odd number n ≥ 3 is an “Orz odd” if and only if there exists a permutation of {1,2,…,n} such as {a1,a2,…,an} can make the following n formulas
a1 – a2 + a3 – a4 + … – an – 1 + an
a2 – a3 + a4 – a5 + … – an + a1
……
an – a1 + a2 – a3 + … – an – 2 + an – 1
are all positive.
Please determine if a given number n is an “Orz odd”.
Input
There are multiple test cases. The first line of input is an integer T indicating the number of test cases. Then T test cases follow.
For each test case:
Line 1. This line contains the single integer n (3 ≤ n ≤ 109).
Output
For each test case:
Line 1. Output “Orz” if n is an “Orz odd”; otherwise output “JiaozhuV5” instead.
Sample Input
2
4
5
Sample Output
JiaozhuV5
Orz
Hint
In the second sample, a permutation of {1,2,3,4,5} is {2,1,3,5,4}.
It can make the following 5 formulas
2 – 1 + 3 – 5 + 4 > 0
1 – 3 + 5 – 4 + 2 > 0
3 – 5 + 4 – 2 + 1 > 0
5 – 4 + 2 – 1 + 3 > 0
4 – 2 + 1 – 3 + 5 > 0
are all positive. So, 5 is an “Orz odd”.
Source
哈理工2012春季校赛 - 现场赛
Author
齐达拉图@HRBUST
【思路分析】这个题想了很久,证明没有证明出来为什么,大致的算证出来了,但是写起来有点麻烦,用STL的next_permiation模拟了一下结果是:n%4=1的时候能使所有式子的结果是整数。
【AC代码】
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n%4==1)//注意取余只要大于0都为逻辑真
{
printf("Orz\n");
}
else
{
printf("JiaozhuV5\n");
}
}
return 0;
}