博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #441 (Div. 2) (ABC)
阅读量:5064 次
发布时间:2019-06-12

本文共 6339 字,大约阅读时间需要 21 分钟。

A. Trip For Meal

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 n times 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.

Examples
Input
3 2 3 1
Output
3
Input
1 2 3 5
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顿饭,求最少走多少路径,n = 1时不需要走 ,n > 1 时,选择a、b中最小的走,然后在与c比较一直走最小的。

1 #include 
2 #define ll long long 3 const int N = 110; 4 using namespace std; 5 6 int main() { 7 int n, a, b, c; 8 cin >> n >> a >> b >> c; 9 if(n == 1) return 0*printf("0\n");10 printf("%d\n",min(a,b)+(n-2)*(min(a,min(b,c))));11 return 0;12 }

 

B. Divisiblity of Differences

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 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.

Examples
Input
3 2 3 1 8 4
Output
Yes 1 4
Input
3 3 3 1 8 4
Output
No
Input
4 3 5 2 7 7 7
Output
Yes 2 7 7
 从n个数中选出k个数,使的每两个数之差都能被m整除。
假设x,y这两个数之差能被m整除即 x%m == y%m   所以b[a[i]]++,  只要b数组中存在大于等于k的数就成立。
1 #include 
2 #define ll long long 3 const int N = 1e5+10; 4 using namespace std; 5 int a[N], b[N]; 6 vector
vs[N]; 7 int main() { 8 int n, k, m, x; 9 cin >> n >> k >> m;10 for(int i = 1; i <= n; i ++) {11 cin >> a[i];12 b[a[i]%m]++;13 vs[a[i]%m].push_back(i);14 }15 for(int i = 0; i <= m; i ++) {16 int len = vs[i].size();17 if(len >= k) {18 printf("Yes\n");19 for(int j = 0; j < k-1; j ++) {20 printf("%d ",a[vs[i][j]]);21 }22 return 0*printf("%d\n",a[vs[i][k-1]]);23 }24 }25 printf("No\n");26 return 0;27 }

 

C. Classroom Watch

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 x was 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.

Examples
Input
21
Output
1 15
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.

 

求是否存在一个数x,使的x加上每个位上的数之和等于n,最大9位  所以从n-81就到n遍历一下就够了。

1 #include 
2 #define ll long long 3 const int N = 110; 4 using namespace std; 5 vector
vs; 6 int fun(int x) { 7 int sum = x; 8 while(x > 0) { 9 sum += x%10;10 x /= 10;11 }12 return sum;13 }14 int main() {15 int n;16 cin >> n;17 for(int i = max(1,n-81); i < n; i ++) {18 if(fun(i) == n) vs.push_back(i);19 }20 if((int)vs.size() == 0) return 0*printf("0\n");21 int len = vs.size();22 printf("%d\n", len);23 for(int i = 0; i < len-1; i ++) {24 printf("%d ", vs[i]);25 }26 printf("%d\n",vs[len-1]);27 return 0;28 }

 

转载于:https://www.cnblogs.com/xingkongyihao/p/7684540.html

你可能感兴趣的文章
Java8 Lambda表达应用 -- 单线程游戏server+异步数据库操作
查看>>
[Unity3D]Unity3D游戏开发MatchTarget的作用攀登效果实现
查看>>
AngularJS学习篇(一)
查看>>
关于Xshell无法连接centos6.4的问题
查看>>
css3动画——基本准则
查看>>
输入月份和日期,得出是今年第几天
查看>>
pig自定义UDF
查看>>
Kubernetes 运维学习笔记
查看>>
spring security 11种过滤器介绍
查看>>
代码实现导航栏分割线
查看>>
大数据学习系列(8)-- WordCount+Block+Split+Shuffle+Map+Reduce技术详解
查看>>
【AS3代码】播放FLV视频流的三步骤!
查看>>
枚举的使用
查看>>
luogu4849 寻找宝藏 (cdq分治+dp)
查看>>
日志框架--(一)基础篇
查看>>
关于源程序到可运行程序的过程
查看>>
转载:mysql数据库密码忘记找回方法
查看>>
scratch少儿编程第一季——06、人在江湖混,没有背景怎么行。
查看>>
【贪心+DFS】D. Field expansion
查看>>
C# Async与Await的使用
查看>>