Petrozavodsk Summer Training Camp 2016 I-Vier(鸽笼原理)

Problem I. Vier
Input file: vier.in
Output file: vier.out
Time limit: 2 seconds
Memory limit: 256 mebibytes
The online game you’ve built in problem “Oha” involves n types of monsters. The monster types are
numbered from 1 to n, and a monster of i-th type has strength i and magical ability πi
. All magical
abilities are different integers between 1 and n, inclusive, in other words, π is a permutation. For
simplicity, you have generated this permutation uniformly at random.
Now you need to choose the starting teams of monsters for the two sides of the game. Each side must
have exactly two monsters in the starting team (they can be of the same type), and the starting teams
must be different. However, in order for the game to be balanced, the starting teams must have the same
total strength modulo n and the same total magical ability modulo n.
More formally, you need to find four integers a, b, c and d between 1 and n such that:
1. a + b ≡ c + d (mod n), and
2. πa + πb ≡ πc + πd (mod n).
Note that the above statements are trivially true when a = c and b = d, or when a = d and b = c. You
need to find any other solution, or report that there isn’t any. Note that it’s allowed for some of the four
integers to coincide — the only restriction is that they can’t coincide in the two ways described in the
first sentence of this paragraph.
Input
The first line of the input file contains one integer n, 2 ≤ n ≤ 106
. The second line of the input file
contains n distinct integers, each between 1 and n. The i-th of those integers gives the value of πi
.
It is guaranteed that the permutation was picked uniformly at random out of all permutations of n
integers.
Output
If a non-trivial solution exists, print Ja on the first line of the output file, otherwise print Nein. In case
you printed Ja, on the second line print four integers between 1 and n: a, b, c and d.
Example
vier.in vier.out
5
2 4 3 5 1
Ja
5 5 1 4
Note
There are 50 non-sample testcases in this problem.


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int vis[1000006];
int num[1000005];
int main()
{
    freopen("vier.in","r",stdin);
    freopen("vier.out","w",stdout);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
    }
    memset(vis,-1,sizeof(vis));
    printf("Ja\n");
    for(int i=0;i<n;i++)
    {
        int now=(num[(i+1)%n]-num[i]+n)%n;
        //cout<<i+1<<' '<<(i+1)%n+1<<endl;
        //cout<<now<<endl;
        if(vis[now]==-1)
            vis[now]=i;
        else if(vis[now]>=0)
        {
            printf("%d %d %d %d\n",i+1,(vis[now]+1)%n+1,vis[now]+1,(i+1)%n+1);
            return 0;
        }
    }
    //cout << "Hello world!" << endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值