码迷,mamicode.com
首页 > 其他好文 > 详细

2020.4.19--个人赛

时间:2020-04-26 11:23:37      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:cin   cee   while   back   pie   app   eve   exist   nali   

A - Buggy Sorting

Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a 1, a 2, ..., a n in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of the program gets number n and array a.


loop integer variable i from 1 to n - 1
    loop integer variable j from i to n - 1
        if (aj > aj + 1), then swap the values of elements aj and aj + 1

But Valera could have made a mistake, because he hasn‘t yet fully learned the sorting algorithm. If Valera made a mistake in his program, you need to give a counter-example that makes his program work improperly (that is, the example that makes the program sort the array not in the non-decreasing order). If such example for the given value of n doesn‘t exist, print -1.

Input

You‘ve got a single integer n (1 ≤ n ≤ 50) — the size of the sorted array.

Output

Print n space-separated integers a 1, a 2, ..., a n (1 ≤ a i ≤ 100) — the counter-example, for which Valera‘s algorithm won‘t work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.

If there are several counter-examples, consisting of nnumbers, you are allowed to print any of them.

Examples

Input
1
Output
-1
#include<stdio.h>
int main()
{
   int n;
   scanf("%d",&n);
   if(n==1||n==2)printf("-1\n");
   else
   {
       //int s[100],k=0;
       for(int i=n;i>0;i--)
       {
           printf("%d ",i);
       }
       printf("\n");
   }
}

B - Increase and Decrease

Polycarpus has an array, consisting of n integers a 1, a 2, ..., an. Polycarpus likes it when numbers in an array match. That‘s why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:

  • he chooses two elements of the array a ia j (i ≠ j);
  • he simultaneously increases number a i by 1 and decreases number a j by 1, that is, executes a i = a i + 1and a j = a j - 1.

The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.

Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a 1, a 2, ..., a n (|a i| ≤ 104) — the original array.

Output

Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.

Examples

Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
#include <iostream>
using namespace std;
 
int main() 
{
    int n,i,a;
    int sum;
    sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        sum+=a;
    }
    if(sum%n==0)
    {
        printf("%d\n",n);
    }
    else
    {
        printf("%d\n",n-1);
    }
    }

C - Beauty Pageant

 

General Payne has a battalion of n soldiers. The soldiers‘ beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.

All soldiers in the battalion have different beauty that is represented by a positive integer. The value a i represents the beauty of the i-th soldier.

On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.

Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.

Input

The first line contains two integers nk (1 ≤ n ≤ 50; 1 ≤ k ≤  技术图片) — the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a 1, a 2, ..., a n (1 ≤ a i ≤ 107) — the beauties of the battalion soldiers.

It is guaranteed that Payne‘s battalion doesn‘t have two soldiers with the same beauty.

Output

Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer c i (1 ≤ c i ≤ n) — the number of soldiers in the detachment on the i-th day of the pageant and c i distinct integers p 1, i, p 2, i, ..., p c i, i — the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.

Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.

Examples

Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12 
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
using namespace std;

typedef struct S {
    int sum;
    bool vis[52];
    int cnt;
} NODE;
NODE node[1300];
int a[52], tot;
vector<int> b;

int main() {
    int n, k, i, j, m, end = 1;
    scanf("%d%d", &n, &k);
    for (i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    node[tot].sum = a[1];
    b.push_back(a[1]);
    memset(node[tot].vis, 0, sizeof (node[tot].vis));
    node[tot].vis[1] = 1;
    node[tot].cnt = 1;
    printf("%d", node[tot].cnt);
    for (j = 1; j <= 1; ++j)
        if (node[tot].vis[j])
            printf(" %d", a[j]);
    printf("\n");
    ++tot;
    if (tot == k)
        return 0;
    for (i = 2; i <= n; ++i) {
        node[tot].sum = a[i];
        if (count(b.begin(), b.end(), node[tot].sum))
            goto L;
        b.push_back(a[i]);
        memset(node[tot].vis, 0, sizeof (node[tot].vis));
        node[tot].vis[i] = 1;
        node[tot].cnt = 1;
        printf("%d", node[tot].cnt);
        for (j = 1; j <= i; ++j)
            if (node[tot].vis[j])
                printf(" %d", a[j]);
        printf("\n");
        ++tot;
        if (tot == k)
            return 0;
        L:
        for (m = 0; m < end; ++m) {
            node[tot].sum = node[m].sum + a[i];
            if (count(b.begin(), b.end(), node[tot].sum))
                continue;
            b.push_back(node[tot].sum);
            for (j = 1; j < i; ++j)
                node[tot].vis[j] = node[m].vis[j];
            node[tot].vis[i] = 1;
            node[tot].cnt = node[m].cnt + 1;
            printf("%d", node[tot].cnt);
            for (j = 1; j <= i; ++j)
                if (node[tot].vis[j])
                    printf(" %d", a[j]);
            printf("\n");
            ++tot;
            if (tot == k)
                return 0;
        }
        end=tot;
    }
    return 0;
}

D - Colorful Graph

 

You‘ve got an undirected graph, consisting of n vertices and m edges. We will consider the graph‘s vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer c i.

Let‘s consider all vertices of the graph, that are painted some color k. Let‘s denote a set of such as V(k). Let‘s denote the value of the neighbouring color diversity for color k as the cardinality of the set Q(k) = {c u :  c u ≠ k and there is vertex v belonging to set V(k) such that nodes v and u are connected by an edge of the graph}.

Your task is to find such color k, which makes the cardinality of set Q(k) maximum. In other words, you want to find the color that has the most diverse neighbours. Please note, that you want to find such color k, that the graph has at least one vertex with such color.

Input

The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers c 1, c 2, ..., c n (1 ≤ c i ≤ 105) — the colors of the graph vertices. The numbers on the line are separated by spaces.

Next m lines contain the description of the edges: the i-th line contains two space-separated integers a i, b i (1 ≤ a i, b i ≤ na i ≠ b i) — the numbers of the vertices, connected by the i-th edge.

It is guaranteed that the given graph has no self-loops or multiple edges.

Output

Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color.

Examples

Input
6 6
1 1 2 3 5 8
1 2
3 2
1 4
4 3
4 5
4 6
Output
3
Input
5 6
4 2 5 2 4
1 2
2 3
3 1
5 3
5 4
3 4
Output
2
#include<stdio.h>
#include<string.h>
#include<queue>
#include<set>
#include<iostream>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#define ll long long
#define mod 1000000007
#define eps 1e-8
using namespace std;
int a[100100];
set<int> s1[100101];
int v[100100];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int maxx=-1;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        v[a[i]]=1;
        maxx=max(maxx,a[i]);//找到最大元素的编号
    }
    for(int i=0;i<m;i++)
    {
        int aa,b;
        scanf("%d%d",&aa,&b);
        if(a[aa]!=a[b])
        {
            s1[a[aa]].insert(a[b]);
            s1[a[b]].insert(a[aa]);
        }
        
    }
    int ans=-1,ot;//ans必须小于0,因为也可能有结果为0
    for(int i=1;i<=maxx;i++)
    {
        int t=s1[i].size();
        if(v[i]&&t>ans)
        {
            ans=t;
            ot=i;
        }
    }
    printf("%d\n",ot);
    return 0;

}

E - Dividing Orange

 

One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k.

There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ a i ≤ n·k). All numbers a i accidentally turned out to be different.

Now the children wonder, how to divide the orange so as to meet these conditions:

  • each child gets exactly n orange segments;
  • the i-th child gets the segment with number a i for sure;
  • no segment goes to two children simultaneously.

Help the children, divide the orange and fulfill the requirements, described above.

Input

The first line contains two integers nk (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a 1, a 2, ..., ak (1 ≤ a i ≤ n·k), where a i is the number of the orange segment that the i-th child would like to get.

It is guaranteed that all numbers a i are distinct.

Output

Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces.

You can print a child‘s segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them.

Examples

Input
2 2
4 1
Output
2 4 
1 3
Input
3 1
2
Output
3 2 1 
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,cnt=1,a[1000],b[35];
    cin>>n>>k;
    for(int i=1;i<=n*k;++i)a[i]=i;
    for(int i=1;i<=k;++i){cin>>b[i];a[b[i]]=0;}
    for(int i=1;i<=k;++i){
        cout<<b[i];//每一行先输出b[i]
        int t=1;//t为计数器,一行输出n个数
        while(t<n){
            if(a[cnt]){cout<< <<a[cnt++];t++;}
            else cnt++;
        }
        cout<<endl;
    }
    return 0;
}

F - Undoubtedly Lucky Numbers

Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.

Let‘s call a positive integer a undoubtedly lucky, if there are such digits x and y (0 ≤ x, y ≤ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.

Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.

Input

The first line contains a single integer n (1 ≤ n ≤ 109) — Polycarpus‘s number.

Output

Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.

Examples

Input
10
Output
10
Input
123
Output
113

Note

In the first test sample all numbers that do not exceed 10are undoubtedly lucky.

In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#define ll long long
using namespace std;

ll n;
set<ll> s;//定义一个集合,就可以快速去重

void dfs(int x,int y,ll ans)
{
    s.insert(ans);
    ll tx=10*ans+x;
    ll ty=10*ans+y;
    if(tx&&tx<=n)//0除外
    dfs(x,y,tx);
    if(ty&&ty<=n)
    dfs(x,y,ty);
}
int main()
{
    while(scanf("%I64d",&n)!=EOF)
    {
        s.clear();
        for(int i=0;i<=9;i++)
        for(int j=0;j<=9;j++)
        {
            dfs(i,j,0);
        }
        printf("%lld\n",s.size()-1);//n除外
    }
}

 

2020.4.19--个人赛

标签:cin   cee   while   back   pie   app   eve   exist   nali   

原文地址:https://www.cnblogs.com/mxw000120/p/12777477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!