zoukankan      html  css  js  c++  java
  • Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力

    B. Dasha and friends

    题目连接:

    http://codeforces.com/contest/761/problem/B

    Description

    Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:

    The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track.

    Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the n barriers. Thus, each of them wrote n integers in the ascending order, each of them was between 0 and L - 1, inclusively.

    Consider an example. Let L = 8, blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down the sequence [2, 4, 6], and Sasha writes down [1, 5, 7].
    There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks.

    Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above.

    Input

    The first line contains two integers n and L (1 ≤ n ≤ 50, n ≤ L ≤ 100) — the number of barriers on a track and its length.

    The second line contains n distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to L - 1 inclusively.

    The second line contains n distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to L - 1 inclusively.

    Output

    Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes).

    Sample Input

    3 8
    2 4 6
    1 5 7

    Sample Output

    YES

    Hint

    题意

    给你一个环,然后让你安排A的起点和B的起点,使得某些特殊点到A的距离是a[i],某些点到B的距离是b[i],问你可不可行。

    题解:

    先把A的起点随便定在一个位置,然后暴力枚举B的起点就好了。

    数据范围大一点好玩一点,这个数据范围太小了,所以自己暴力就行了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1005;
    int p[maxn],n,l,a[maxn],b[maxn],c[maxn];
    int main()
    {
        scanf("%d%d",&n,&l);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]),p[a[i]]=1;
        for(int j=0;j<n;j++)
            scanf("%d",&b[j]);
        for(int i=0;i<l;i++){
            memset(c,0,sizeof(c));
            int now=i;
            for(int j=0;j<n;j++)
                c[(now+b[j])%l]=1;
            int flag = 0;
            for(int j=0;j<l;j++)
            {
                if(c[j]!=p[j])
                {
                    flag = 1;
                    break;
                }
            }
            if(flag==0){
                cout<<"YES"<<endl;
                return 0;
            }
        }
        cout<<"NO"<<endl;
    }
  • 相关阅读:
    ld: cannot find lXXX" 如lpthread lgomp
    Glib交叉编译:g__cancellable_lock undeclared!&HEADER/C_IN undeclared!&undefined reference to "localeconv"
    Android_清除/更新Bundle中的数据(不finish() Activity的情况下)
    读Kernel感悟Linux内核启动从hello world说起
    细数二十世纪最伟大的十大算法
    error: *** No iconv() implementation found in C library & libiconv 交叉编译 失败编译
    gnulib+glib+glibc+libc的不同转
    [Android] 以singleInstance模式加载的Activity怎么接收以Bundle方式传递过来的参数 By onNewIntent() but not onResum
    Glib在armlinux下的交叉编译
    python 笔记
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6359968.html
Copyright © 2011-2022 走看看