zoukankan      html  css  js  c++  java
  • Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

                                    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.

    题解:只有三边,分类讨论就好

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int kase,n;
     5 
     6 int main()
     7 {   scanf("%d",&kase);
     8     while(kase--){
     9         scanf("%d",&n);
    10         if(n==1||n==2||n==3){ cout<<"-1"<<endl; continue; }
    11         if(n%2==0) cout<<n/2/2<<endl;
    12         else{
    13             int ans=n/2-4;
    14             if(ans==0) cout<<"1"<<endl;
    15             else if(ans<0||ans==1) cout<<"-1"<<endl;
    16             else cout<<ans/2+1<<endl;
    17         }
    18     }
    19     return 0;
    20 } 

                                    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
    题解:很有意思的一道题,利用余数的性质,只有模m的余数相同,其差值一定能整除m
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 const int maxn=1e5+5;
     5 
     6 int n,k,m;
     7 int a[maxn],b[maxn];
     8 
     9 int main()
    10 {   cin>>n>>k>>m;
    11     memset(b,0,sizeof(b));
    12     int ans=-1;
    13     for(int i=1;i<=n;i++){
    14         scanf("%d",&a[i]);
    15         int temp=a[i]%m;
    16         b[temp]++;
    17         if(b[temp]>=k) ans=temp; 
    18     }
    19     if(ans==-1) cout<<"No"<<endl;
    20     else{
    21         int cnt=0;
    22         cout<<"Yes"<<endl;
    23         for(int i=1;i<=n;i++){
    24             if(a[i]%m==ans){
    25                 cnt++;
    26                 printf("%d%c",a[i],cnt==k?'
    ':' ');
    27                 if(cnt==k) break;
    28             } 
    29         }
    30     }
    31     return 0;
    32 }

                                  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.

    题解:int范围内的数,各位数之和最大不超过100,所以直接在离n距离100范围内数找就行。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 const int maxn=1e5;
     5 
     6 int n,a[maxn];
     7 
     8 int made(int x){
     9     int ans=x;
    10     while(x){
    11         ans+=x%10;
    12         x/=10;
    13     }
    14     return ans;
    15 }
    16 
    17 int main()
    18 {   cin>>n;
    19     int m;
    20     if(n<=1000) m=1;
    21     else m=n-100;
    22     
    23     int cnt=0;
    24     for(int i=m;i<=n;i++){
    25         int temp=made(i);
    26         if(temp==n) a[cnt++]=i;
    27     }
    28     cout<<cnt<<endl;
    29     for(int i=0;i<cnt;i++) printf("%d%c",a[i],i==cnt-1?'
    ':' ');
    30     return 0;
    31 }



  • 相关阅读:
    面试生信工程师2
    R语言矩阵相关性计算及其可视化?
    PCA方差解释比例求解与绘图?
    MySQL 练习
    oracle高级数据查询技术
    Oracle安全管理
    基本查询语句
    管理表
    oracle PL/SQL高级编程
    oracle视图与索引
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/7684042.html
Copyright © 2011-2022 走看看