CodeForces
来源:互联网 发布:淘宝怎么看卖家的评价 编辑:程序博客网 时间:2024/06/10 02:09
A - A
CodeForces - 876AWinnie-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 Input3231
Output3
Input1235
Output0
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
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.
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 one number — minimum distance in meters Winnie must go through to have a meal n times.
3231
3
1235
0
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 - 876BYou 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 n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ 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 Input3 2 31 8 4
OutputYes1 4
Input3 3 31 8 4
OutputNo
Input4 3 52 7 7 7
OutputYes2 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
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.
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ 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.
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.
3 2 31 8 4
Yes1 4
3 3 31 8 4
No
4 3 52 7 7 7
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 - 876CEighth-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 Input21
Output115
Input20
Output0
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;}
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.
The first line contains integer n (1 ≤ n ≤ 109).
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.
21
115
20
0
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;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- java学习资源分享
- JAVA配置相关注意事项和javac不是内部或外部命令的处理办法
- 六级_第十四天
- Python的计时timeit模块概述
- 1·RHCSA重设root密码
- CodeForces
- 栈的存储结构
- Java8 I/O源码-BufferedReader与BufferedWriter
- chapter20 Netty架构剖析
- SDK在Android Studio中的配置陷阱
- JAVA-JDK配置-JDK下载安装以及环境变量配置(win10)
- KNN(K最临近算法)的python实现
- java日志组件介绍(common-logging,log4j,slf4j,logback )
- 分布式数据库