CodeForces

来源:互联网 发布:淘宝怎么看卖家的评价 编辑:程序博客网 时间:2024/06/10 02:09

A - A

 CodeForces - 876A

Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is c meters.

For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal ntimes a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).

Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.

Input

First line contains an integer n (1 ≤ n ≤ 100) — number of visits.

Second line contains an integer a (1 ≤ a ≤ 100) — distance between Rabbit's and Owl's houses.

Third line contains an integer b (1 ≤ b ≤ 100) — distance between Rabbit's and Eeyore's houses.

Fourth line contains an integer c (1 ≤ c ≤ 100) — distance between Owl's and Eeyore's houses.

Output

Output one number — minimum distance in meters Winnie must go through to have a meal n times.

Example
Input
3231
Output
3
Input
1235
Output
0
Note

In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.

In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.

 
/*题意:给出n代表蹭饭的次数,给出3个点之间的距离,而某某是个吃货,想吃最多的饭,走最少的路起点是自己家,也就是支持一顿饭在自家解决即可,出0;其他简单模拟*/#include<iostream>#include<stdio.h>using namespace std;#define N 1000000000#define ll long longint min(int a,int b){    return a<b?a:b;}int main(){    int n;    int a,b,c;    ll ans=0;    int step=1;    cin>>n>>a>>b>>c;    for(int i=1;i<n;i++)    {        if(b<=a&&step==1)        {            ans+=b;            step=3;        }        else if(b>a&&step==1)        {            ans+=a;            step=2;        }        else if(b<=c&&step==3)        {            ans+=b;            step=1;        }        else if(b>c&&step==3)        {            ans+=c;            step=2;        }        else if(a<=c&&step==2)        {            ans+=a;            step=1;        }        else if(a>c&&step==2)        {            ans+=c;            step=3;        }    }    cout<<ans<<endl;    return 0;}

B - B

 CodeForces - 876B 

You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.

Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.

Input

First line contains three integers nk and m (2 ≤ k ≤ n ≤ 100 0001 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.

Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.

Output

If it is not possible to select k numbers in the desired way, output «No» (without the quotes).

Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.

Example
Input
3 2 31 8 4
Output
Yes1 4 
Input
3 3 31 8 4
Output
No
Input
4 3 52 7 7 7
Output
Yes2 7 7 
/*题意:n,m,mod  n个数从这n个数里面找出对mod取余相等的数,如果个数大于等于m输出m个数(符合条件的),否则No思路:找出所有的余数,记录个数,找到最多的那一个,记下此时的余数,遍历*/#include<iostream>#include<stdio.h>#include<string.h>#include<map>#include<string>using namespace std;#define N 100010#define ll long longint vis[N];int num,a[N],b[N],c[N];int main(){    int n,m,mod;    int temp,flag=0;    cin>>n>>m>>mod;    for(int i=1;i<=n;i++)    {        scanf("%d",&a[i]);        temp=a[i]%mod;        b[i]=temp;        c[temp]++;    }    for(int i=0;i<mod;i++)        if(c[i]>=m)        {            flag=1;            num=i;            break;        }    temp=0;    if(flag==1)    {        cout<<"Yes"<<endl;        for(int i=1;i<=n;i++)            if(b[i]==num)            {                temp++;                if(temp==m)                {                    printf("%d\n",a[i]);                    break;                }                else                printf("%d ",a[i]);            }    }    else cout<<"No"<<endl;    return 0;}

C - C

 CodeForces - 876C 

Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer xwas given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.

Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.

Input

The first line contains integer n (1 ≤ n ≤ 109).

Output

In the first line print one integer k — number of different values of x satisfying the condition.

In next k lines print these values in ascending order.

Example
Input
21
Output
115
Input
20
Output
0
Note

In the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.

In the second test case there are no such x.

/*题意:略思路:直接暴力一发,超时,立刻换了方式,上限10^9,这些书中最大的也就是9个9,和是81,也就是答案一定在[n-81,n]之间*/#include<iostream>#include<stdio.h>using namespace std;#define N 1000000000#define ll long longll map[1000000];int max(int a,int b){    return a>b?a:b;}ll change(ll n){    ll ans=0;    while(n>0)    {        ans+=(n%10);        n/=10;    }    return ans;}int main(){    ll n;    ll temp=0,num=0;    scanf("%lld",&n);    for(int i=max(1,n-82);i<n;i++)    {        if(i+change(i)==n)        {            map[num++]=i;        }    }    printf("%d\n",num);    for(int i=0;i<num;i++)    {        printf("%lld\n",map[i]);    }    return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 居住证凭证丢了怎么办 上海市居住证过期了怎么办 上海居住证积分不够怎么办 居住证登录密码忘记怎么办 投靠中考上海居住证怎么办 嫁入广州户口怎么办 上海积分扣完了怎么办 公立小学积分不够怎么办 查不到户口信息怎么办 小孩上不到户口怎么办 离开上海上海户口怎么办? 上海没房户口怎么办 没有房照动迁怎么办 持有上海居住证怎么办准生证 换公司后公积金怎么办 换工作了住房公积金怎么办 以前买的户口怎么办 上海落户积分不够怎么办 带坏受孕了怎么办 对公转账转错了怎么办 对公转错账怎么办 银行卡转错了怎么办 人户分离证明怎么办 暂居证怎么办才快 房产证户口本信息泄漏怎么办 户主迁走了户口怎么办 户口本丢了应该怎么办 户口本遗失了应该怎么办 户口迁出河南怎么办居住证 居住证学历写错怎么办 换单位了档案怎么办 辞职一年了档案怎么办 上海租房网签怎么办 户口本主页掉了怎么办 居转户办理中离职怎么办 上海居转户没有职称怎么办 上海居转户0税单怎么办 居转户出现零税怎么办 遇假记者敲诈怎么办 液氮挥发太快怎么办 高铁上空调太冷怎么办