哈理工OJ 1391 Orz odd(规律【没证出来】)

题目链接: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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值