首页 > 其他 > 详细

2020.4.5--个人赛

时间:2020-04-12 21:32:48      阅读:58      评论:0      收藏:0      [点我收藏+]

A.

Petr stands in line of n people, but he doesn‘t know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than bpeople standing behind him. Find the number of different positions Petr can occupy.

Input

The only line contains three integers na and b (0 ≤ a, b < n ≤ 100).

Output

Print the single number — the number of the sought positions.

Examples

Input
3 1 1
Output
2
Input
5 2 3
Output
3

Note

The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).

In the second sample they are 3, 4 and 5.

#include<stdio.h>
int main()
{
    int n,a,b;
    while(scanf("%d%d%d",&n,&a,&b)!=EOF){
    int k,l;
    k=n-a;
    l=b+1;
    printf("%d\n",k>l?l:k);
    }
}

B - Permutations

 You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.

Input

The first line contains integers n and k — the number and digit capacity of numbers correspondingly (1 ≤ n, k ≤ 8). Next n lines contain k-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits.

Output

Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule.

Examples

Input
6 4
5237
2753
7523
5723
5327
2537
Output
2700
Input
3 3
010
909
012
Output
3
Input
7 5
50808
36603
37198
44911
29994
42543
50156
Output
20522

Note

In the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).

In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102.

题意: 
给出n个k位的数字的序列,现在可以对每一个数字进行相同的操作,比如,你把第1个数字的第1,2位互换了,那么剩余的n-1个数字你也必须把第1,2位互换。现在对这n个数字一系列操作后,会产生许多不同的序列,输出min{序列的max-序列的min 
思路: 
把所有情况搜出来

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
char s[100][100],str[100];
int vis[100],k,cha,b[100],n;
#define inf 99999999
void dfs(int wei)
{
int i,j,minx=inf,maxx=-inf,num;
if(wei==k+1){
num=0;
for(i=1;i<=n;i++){
num=0;
for(j=1;j<=k;j++){
num=num*10+s[i][b[j]]-0;
}
maxx=max(maxx,num);
minx=min(minx,num);
}
cha=min(cha,maxx-minx);//return;
}
else{
for(i=1;i<=k;i++){
if(!vis[i]){
vis[i]=1;
b[wei]=i;
dfs(wei+1);
vis[i]=0;
}
}
}
}
int main()
{
int m,i,j,t,num;
char c;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(i=1;i<=n;i++){
scanf("%s",s[i]+1);
}
cha=inf;
if(n==1){
printf("0\n");continue;
}
memset(vis,0,sizeof(vis));
dfs(1);
printf("%d\n",cha);
}
return 0;
}

C - Prime Permutation

 You are given a string s, consisting of small Latin letters. Let‘s denote the length of the string as |s|. The characters in the string are numbered starting from 1.

Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s|and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters.

Input

The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000).

Output

If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO".

Examples

Input
abc
Output
YES
abc
Input
abcd
Output
NO
Input
xxxyxxx
Output
YES
xxxxxxy

Note

In the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".

In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).

In the third test any string where character "y" doesn‘t occupy positions 2, 3, 4, 6 will be valid.

题意:输入一个字符串,判断能否使每一质数和其倍数位上的字符均相同,能输出YES和任一合法解,否则输出NO

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int prime[5000],fa[5000],n,t[500000];
char pr[500000];
struct node{
      int t,pl;
}num[50];
struct hhh{
      int t,pl;
}num[50];
struct hhh{
      int t,pl;
}sum[100000];
void init()
{     int i,j,k;
      memset(prime,1,sizeof(prime));
      prime[1]=prime[0]=0;
      fa[1]=1;
      fa[0]=0;
      for(i=2;i<=1100;i++)
         if(prime[i]){
           fa[i]=i;
           for(j=i*2;j<=1100;j+=i){
             prime[j]=0;
             if(!fa[j]);
               fa[j]=i;
           }
         }
}
int sf(int x)
{     return (fa[x]==x?x:fa[x]=sf(fa[x]));
}
void merge()
{     int i,j,k;
      for(i=2;i<=n;i++)
         if(prime[i])
           for(j=i+1;j<=n;j++)
             if(prime[j])
               if(i*j<=n&&fa[i]!=fa[j]){
                   int x,y;
                   x=sf(i);
                   y=sf(j);
                   if(x!=y)
                     fa[y]=x;
               }
}
bool cmp(const node &x,const node &y)
{     return x.t>y.t;
}
bool cmp2(const hhh &x,const hhh &y)
{     return x.t>y.t;
}
int main()
{     int m,i,j,k;
      string s;
      cin>>s;
      n=s.size();
      for(i=0;i<n;i++)
         num[s[i]-a+1].t++;
      init();
      merge();
      for(i=1;i<=27;i++)
         num[i].pl=i;
      for(i=1;i<=n;i++)
         sum[sf(i)].t++;
      for(i=1;i<=n;i++)
         sum[i].pl=i;
      sort(sum+1,sum+n+1,cmp2);
      sort(num+1,num+27,cmp);
      k=1;
      while(num[1].t){
          if(!sum[k].t)continue;
          if(num[1].t<sum[k].t){
              puts("NO");
              return 0;
          }
          num[1].t-=sum[k].t;
          t[sum[k].pl]=num[1].pl;
          k++;
          sort(num+1,num+27,cmp);
      }
      puts("YES");
      for(i=1;i<=n;i++)
         pr[i]=t[fa[i]]-1+a;
      for(i=1;i<=n;i++)
         cout<<pr[i];
      cout<<endl;
      return 0;
}

D - cAPS lOCK

wHAT DO WE NEED cAPS LOCK FOR?

Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.

Let‘s consider that a word has been typed with the Caps lock key accidentally switched on, if:

  • either it only contains uppercase letters;
  • or all letters except for the first one are uppercase.

In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.

Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.

Input

The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word‘s length is from 1 to 100 characters, inclusive.

Output

Print the result of the given word‘s processing.

Examples

Input
cAPS
Output
Caps
Input
Lock
Output
Lock
#include<stdio.h>
#include<string.h>
char s[1000];
int main()
{

    while(scanf("%s",&s)!=EOF)
    {
        int n;
        n=strlen(s);
        if(n==1){
           if(s[0]>=A&&s[0]<=Z)s[0]+=32;
           else s[0]-=32;
           puts(s);
        }
        else{

            if(s[0]>=a&&s[0]<=z)
            {
                int k=0;
                for(int i=1;i<n;i++)
                {
                    if(s[i]>=A&&s[i]<=Z)
                    {
                        k=1;
                    }
                    else{
                        k=0;
                        break;
                    }
                }
                if(k==1){
                        s[0]-=32;
                    for(int i=1;i<n;i++)
                    {
                        s[i]+=32;
                    }
                    puts(s);
                }
                else puts(s);
            }
            else {
                    int l=0;
                for(int i=0;i<n;i++)
                {
                    if(s[i]>=A&&s[i]<=Z)
                    {
                        l=1;
                    }
                    else {
                        l=0;
                        break;
                    }
                }
                if(l==1){
                    for(int i=0;i<n;i++)
                    {
                        s[i]+=32;
                    }
                    puts(s);
                }
                else puts(s);
            }

    }
    }
}

E - Opposites Attract

 Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of customers.

"Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of t. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence t1, t2, ..., tn. For example, if t = (1,  - 1, 1,  - 1), then any two elements ti and tj form a couple if i and j have different parity. Consequently, in this case the sought number equals 4.

Of course, a client can‘t form a couple with him/herself.

Input

The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-th customer that has been assigned to the customer by the result of the analysis of his interests.

Output

Print the number of couples of customs with opposite t. The opposite number for x is number  - x (0 is opposite to itself). Couples that only differ in the clients‘ order are considered the same.

Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

Examples

Input
5
-3 3 0 0 3
Output
3
Input
3
0 0 0
Output
3

Note

In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).

In the second sample any couple of clients is opposite.

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
 
int main()
{
    int n,i,j;
    int a;
    double b[21];
    double sum;
    sum=0;
    scanf("%d",&n);
    for(i=0;i<21;i++)
    {
        b[i]=0;
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        b[a+10]++;
    }
    for(i=0;i<10;i++)
    {
        sum+=b[i]*b[20-i];
    }
    sum+=b[10]*(b[10]-1)/2;
 
    printf("%.0lf\n",sum);
    
    return 0;
}

F - The World is a Theatre

There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory", they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of course, the variants that only differ in the composition of the troupe are considered different.

Perform all calculations in the 64-bit type: long long for С/С++, int64 for Delphi and long for Java.

Input

The only line of the input data contains three integers nmt (4 ≤ n ≤ 30, 1 ≤ m ≤ 30, 5 ≤ t ≤ n + m).

Output

Find the required number of ways.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

Examples

Input
5 2 5
Output
10
Input
4 3 5
Output
3
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include<set>
#include <algorithm>
using namespace std;
 
long long c[64][64];
long long res;
int main()
{
    int n,m,t;
    int i,j;
    scanf("%d %d %d",&n,&m,&t);
    for(i=0;i<=30;i++) 
    {
        c[i][0]=1;
        for(j=1;j<=i;j++)
        {
            c[i][j]=c[i-1][j-1]+c[i-1][j];
        }
    }
    res=0;
    for( i=4;i<t;i++)
    {
        res += c[n][i]*c[m][t-i];
    }
    printf("%lld\n",res);
    return 0;
}

 

2020.4.5--个人赛

原文:https://www.cnblogs.com/mxw000120/p/12687761.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!