Educational Codeforces Round 83 (Rated for Div. 2)

A. Two Regular Polygons

You are given two integers n and m (m<n). Consider a convex regular polygon of n vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length).
Examples of convex regular polygons
Your task is to say if it is possible to build another convex regular polygon with m vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon.
You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1≤t≤104) — the number of test cases.
The next t lines describe test cases. Each test case is given as two space-separated integers n and m (3≤m<n≤100) — the number of vertices in the initial polygon and the number of vertices in the polygon you want to build.

Output

For each test case, print the answer — “YES” (without quotes), if it is possible to build another convex regular polygon with m vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon and “NO” otherwise.

Example

input

2
6 3
7 3

output

YES
NO

题意:两个正多边形的顶点是否能完全重合。

思路:签到。边数为a,b(a>b)满足a%b==0即可。

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n, m;
        cin >> n >> m;
        if(n%m==0){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

B. Bogosort

You are given an array a1,a2,…,an. Array is good if for each pair of indexes i<j the condition j−aj≠i−ai holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).
For example, if a=[1,1,3,5], then shuffled arrays [1,3,5,1], [3,5,1,1] and [5,3,1,1] are good, but shuffled arrays [3,1,5,1], [1,1,3,5] and [1,1,5,3] aren’t.
It’s guaranteed that it’s always possible to shuffle an array to meet this condition.

Input

The first line contains one integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains one integer n (1≤n≤100) — the length of array a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤100).

Output

For each test case print the shuffled version of the array a which is good.

Example

input

3
1
7
4
1 1 3 5
6
3 2 1 5 6 4

output

7
1 5 1 3
2 4 6 1 3 5

题意:给一组数组,要求排序,使得任意i,j,i-a[i]!=j-a[j]。

思路:水题,从大到小sort一下即可。

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))

bool cmp(int x, int y)
{
    return x > y;
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        int s[110];
        for(int i = 1; i <= n; i++) cin >> s[i];
        if(n==1){
            cout << s[1] << endl;
        }else{
            sort(s+1,s+n+1,cmp);
            for(int i = 1; i <= n; i++) cout << s[i] << " ";
            cout << endl;
        }
    }
    return 0;
}

C. Adding Powers

Suppose you are performing the following algorithm. There is an array v1,v2,…,vn filled with zeroes at start. The following operation is applied to the array several times — at i-th step (0-indexed) you can:
either choose position pos (1≤pos≤n) and increase vpos by ki;
or not choose any position and skip this step.
You can choose how the algorithm would behave on each step and when to stop it. The question is: can you make array v equal to the given array a (vj=aj for each j) after some step?

Input

The first line contains one integer T (1≤T≤1000) — the number of test cases. Next 2T lines contain test cases — two lines per test case.
The first line of each test case contains two integers n and k (1≤n≤30, 2≤k≤100) — the size of arrays v and a and value k used in the algorithm.
The second line contains n integers a1,a2,…,an (0≤ai≤1016) — the array you’d like to achieve.

Output

For each test case print YES (case insensitive) if you can achieve the array a after some step or NO (case insensitive) otherwise.

Example

input

5
4 100
0 0 0 0
1 2
1
3 4
1 4 1
3 2
0 1 3
3 9
0 59049 810

output

YES
YES
NO
NO
YES

题意:给定一个n个元素的数组,要求判断是否能由一个全为0的数组,加上k的i次(i==1,2,3,4…)相加得到,并且i不能重复。

思路:先排序,找到最大的元素,得出i的最大值,然后把每个元素按照依次减去比自己大的k的i次,判断能不能由k的i次组成,如果能,统计i的数量,不能直接输出NO,最后判断每个i的个数,有大于1的则输出NO,反之YES。

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        ull n, k;
        cin >> n >> k;
        ull s[100];
        for(int i = 0; i < n; i++) cin >> s[i];
        sort(s,s+n);
        int flag = 1;
        ull cnt = 0;
        ull maxn = s[n-1];
        ull x = 1;
        while(x<=maxn){
            cnt++;
            x = pow(k,cnt);
        }
        ull q[100];
        mem(q);
        for(int i = 0; i < n; i++){
            if(s[i]!=0){
                ull y = s[i];
                for(int j = cnt-1; j >= 0; j--){
                    ull z = pow(k,j);
                    if(y>=z) y -= z;
                }
                if(y==0){
                    y = s[i];
                    for(int j = cnt-1; j >= 0; j--){
                        ull z = pow(k,j);
                        if(y>=z){
                            y -= z;
                            q[j]++;
                        }
                    }
                }else{
                    flag = 0;
                    break;
                }
            }
        }
        for(int i = 0; i < cnt; i++){
            if(q[i]>1){
                flag = 0;
                break;
            }
        }
        if(flag==1){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值