CF761 B. Dasha and friends(水题)
2017-02-01 11:55
495 查看
传送门
B. Dasha and friends
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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).
Examples
input
output
input
output
input
output
Note
The first test is analyzed in the statement.
题目大意:在跑道上有n个障碍,跑道一圈长度为L,给你两个人他们的位置到n个障碍的距离,问他们是否在同一条跑道上。不同的跑道障碍物的位置不一样,障碍物之间的距离不一定相等。
解题思路:算出他们障碍物之间的距离,然后匹配是否相等。
/* ***********************************************
┆ ┏┓ ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃ ┃ ┆
┆┃ ━ ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃ ┃ ┆
┆┃ ┻ ┃ ┆
┆┗━┓ 马 ┏━┛ ┆
┆ ┃ 勒 ┃ ┆
┆ ┃ 戈 ┗━━━┓ ┆
┆ ┃ 壁 ┣┓┆
┆ ┃ 的草泥马 ┏┛┆
┆ ┗┓┓┏━┳┓┏┛ ┆
┆ ┃┫┫ ┃┫┫ ┆
┆ ┗┻┛ ┗┻┛ ┆
************************************************ */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <bitset>
using namespace std;
#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
#define pb push_back
#define mp make_pair
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define MS0(X) memset((X), 0, sizeof((X)))
#define SelfType int
SelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}
SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}
#define Sd(X) int (X); scanf("%d", &X)
#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define all(a) a.begin(), a.end()
#define mem(x,v) memset(x,v,sizeof(x))
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}
int a[55],b[55];
int aa[120],bb[120];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int n,L;
n = read(), L = read();
rep(i,1,n) a[i] = read();
rep(i,1,n) b[i] = read();
rep(i,2,n)
{
aa[i-1] = a[i] - a[i-1];
bb[i-1] = b[i] - b[i-1];
}
aa
= (L- a
+a[1]);
bb
= (L-b
+b[1]);
rep(i,n+1,2*n)
{
aa[i] = aa[i-n];
bb[i] = bb[i-n];
}
int flag = 0;
for(int i=1;i<=n;i++)
{
if(aa[1]==bb[i])
{
int p = 1;
for(int j=i+1,k=2;j<=i+n;j++,k++)
{
if(aa[k]!=bb[j])
{
p = 0;
break;
}
}
if(p==1)
{
flag = 1;
break;
}
}
}
if(flag)
puts("YES");
else puts("NO");
return 0;
}
B. Dasha and friends
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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).
Examples
input
3 8 2 4 6 1 5 7
output
YES
input
4 9 2 3 5 8 0 1 3 6
output
YES
input
2 4 1 3 1 2
output
NO
Note
The first test is analyzed in the statement.
题目大意:在跑道上有n个障碍,跑道一圈长度为L,给你两个人他们的位置到n个障碍的距离,问他们是否在同一条跑道上。不同的跑道障碍物的位置不一样,障碍物之间的距离不一定相等。
解题思路:算出他们障碍物之间的距离,然后匹配是否相等。
/* ***********************************************
┆ ┏┓ ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃ ┃ ┆
┆┃ ━ ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃ ┃ ┆
┆┃ ┻ ┃ ┆
┆┗━┓ 马 ┏━┛ ┆
┆ ┃ 勒 ┃ ┆
┆ ┃ 戈 ┗━━━┓ ┆
┆ ┃ 壁 ┣┓┆
┆ ┃ 的草泥马 ┏┛┆
┆ ┗┓┓┏━┳┓┏┛ ┆
┆ ┃┫┫ ┃┫┫ ┆
┆ ┗┻┛ ┗┻┛ ┆
************************************************ */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <bitset>
using namespace std;
#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
#define pb push_back
#define mp make_pair
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define MS0(X) memset((X), 0, sizeof((X)))
#define SelfType int
SelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}
SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}
#define Sd(X) int (X); scanf("%d", &X)
#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define all(a) a.begin(), a.end()
#define mem(x,v) memset(x,v,sizeof(x))
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}
int a[55],b[55];
int aa[120],bb[120];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int n,L;
n = read(), L = read();
rep(i,1,n) a[i] = read();
rep(i,1,n) b[i] = read();
rep(i,2,n)
{
aa[i-1] = a[i] - a[i-1];
bb[i-1] = b[i] - b[i-1];
}
aa
= (L- a
+a[1]);
bb
= (L-b
+b[1]);
rep(i,n+1,2*n)
{
aa[i] = aa[i-n];
bb[i] = bb[i-n];
}
int flag = 0;
for(int i=1;i<=n;i++)
{
if(aa[1]==bb[i])
{
int p = 1;
for(int j=i+1,k=2;j<=i+n;j++,k++)
{
if(aa[k]!=bb[j])
{
p = 0;
break;
}
}
if(p==1)
{
flag = 1;
break;
}
}
}
if(flag)
puts("YES");
else puts("NO");
return 0;
}
相关文章推荐
- CF761 A. Dasha and Stairs (水题)
- CodeForces-761A-Dasha and Stairs [水题]
- B. Dasha and friends
- CF761 C. Dasha and Password (DP)
- Codeforces Round #394(Div. 2)A.Dasha and Stairs【水题】
- Codeforces Round #394(Div. 2)B. Dasha and friends【思维+暴力】
- Codeforces Round #394 (Div. 2) B. Dasha and friends
- codeforces#292B_Drazil and His Happy Friends-暴力水题
- B. Dasha and friends
- codeforces761 B. Dasha and friends
- 【codeforces 761B】Dasha and friends
- Codeforces Round #394 (Div. 2)(A. Dasha and Stairs,B. Dasha and friends,C. Dasha and Password)
- 【VK Cup 2016 - Round 1 (Div 2 Edition)B】【水题】Bear and Displayed Friends 即时维护最大6个数
- Codeforces Round #394 (Div. 2)Dasha and friends
- Codeforces Round #394 (Div. 2) B. Dasha and friends(暴力)
- Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题
- Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力
- Codeforces-Round 394#B-Dasha and friends
- Codeforces 761B-Dasha and friends
- Dasha and friends