• Codeforces Round #451 (Div. 2) ABC


    A. Rounding

    Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded.

    For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct.

    For given n find out to which integer will Vasya round it.

    Input

    The first line contains single integer n (0 ≤ n ≤ 109) — number that Vasya has.

    Output

    Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer.

    Examples
    input
    5
    output
    0
    input
    113
    output
    110
    input
    1000000000
    output
    1000000000
    input
    5432359
    output
    5432360
    Note

    In the first example n = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.

     变成能整除10的数,求最近的一个数

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main() {
     5     int n;
     6     cin >> n;
     7     int x = n%10;
     8     if(x <= 5) printf("%d
    ",n-x);
     9     else printf("%d
    ",n+(10-x));
    10     return 0;
    11 }
    B. Proper Nutrition

    Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.

    Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles.

    In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x·a + y·b = n or tell that it's impossible.

    Input

    First line contains single integer n (1 ≤ n ≤ 10 000 000) — amount of money, that Vasya has.

    Second line contains single integer a (1 ≤ a ≤ 10 000 000) — cost of one bottle of Ber-Cola.

    Third line contains single integer b (1 ≤ b ≤ 10 000 000) — cost of one Bars bar.

    Output

    If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly n burles print «NO» (without quotes).

    Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers x and y — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x·a + y·b = n. If there are multiple answers print any of them.

    Any of numbers x and y can be equal 0.

    Examples
    input
    7
    2
    3
    output
    YES
    2 1
    input
    100
    25
    10
    output
    YES
    0 10
    input
    15
    4
    8
    output
    NO
    input
    9960594
    2551
    2557
    output
    YES
    1951 1949
    Note

    In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.

    In second example Vasya can spend exactly n burles multiple ways:

    • buy two bottles of Ber-Cola and five Bars bars;
    • buy four bottles of Ber-Cola and don't buy Bars bars;
    • don't buy Ber-Cola and buy 10 Bars bars.

    In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly n burles.

    求ax+bx=n,可以暴力。

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 
     5 int main(){
     6     ll a, b, n, x = 0;
     7     cin >> n >> a >> b;
     8     for(; x*a <= n && (n-x*a)%b != 0; x++);
     9     if(x*a <= n) {
    10         printf("YES
    ");
    11         cout << x << " " << (n-x*a)/b << endl;
    12     }
    13     else printf("NO
    ");
    14     return 0;
    15 }
    C. Phone Numbers

    Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.

    Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record.

    Vasya also believes that if the phone number a is a suffix of the phone number b (that is, the number b ends up with a), and both numbers are written by Vasya as the phone numbers of the same person, then a is recorded without the city code and it should not be taken into account.

    The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers x and y, and x is a suffix of y (that is, y ends in x), then you shouldn't print number x. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once.

    Read the examples to understand statement and format of the output better.

    Input

    First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books.

    The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros.

    Output

    Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books.

    The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend.

    Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order.

    Examples
    input
    2
    ivan 1 00123
    masha 1 00123
    output
    2
    masha 1 00123
    ivan 1 00123
    input
    3
    karl 2 612 12
    petr 1 12
    katya 1 612
    output
    3
    katya 1 612
    petr 1 12
    karl 1 612
    input
    4
    ivan 3 123 123 456
    ivan 2 456 456
    ivan 8 789 3 23 6 56 9 89 2
    dasha 2 23 789
    output
    2
    dasha 2 23 789
    ivan 4 789 123 2 456

     模拟题吧,每个人都有一些号码,当a的后缀出现b时,b号码可以删除掉,求最后没有后缀的号码。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 vector<string> vs[22];
     4 map<string, int> mp;
     5 map<int, string> mp1;
     6 int main() {
     7     int n, m;
     8     string s, ss;
     9     cin >> n;
    10     int ans = 1;
    11     for(int i = 1; i <= n; i ++) {
    12         cin >> s >> m;
    13         if(mp[s] == 0) {
    14             mp1[ans] = s;
    15             mp[s] = ans++;
    16         }
    17         for(int j = 1; j <= m; j ++) {
    18             cin >> ss;
    19             reverse(ss.begin(), ss.end());
    20             int len = vs[mp[s]].size();
    21             bool flag = true;
    22             for(int k = 0; k < len; k ++) {
    23                 if(vs[mp[s]][k].find(ss) == 0) {
    24                     flag = false;
    25                     break;
    26                 } 
    27                 if(ss.find(vs[mp[s]][k]) == 0) {
    28                     flag = false;
    29                     vs[mp[s]].erase(vs[mp[s]].begin()+k);
    30                     vs[mp[s]].push_back(ss);
    31                     break;
    32                 }
    33             }
    34             if(flag) vs[mp[s]].push_back(ss);
    35         }
    36     }
    37     printf("%d
    ",ans-1);
    38     for(int i = 1; i < ans; i ++) {
    39         cout << mp1[i];
    40         printf(" %d", vs[i].size());
    41         for(int j = 0; j < vs[i].size(); j ++) {
    42             reverse(vs[i][j].begin(), vs[i][j].end());
    43             cout << " " << vs[i][j];
    44         }
    45         cout << endl;
    46     }
    47     return 0;
    48 }
  • 相关阅读:
    获取屏幕分辨率
    String-去除-指定-字符-操作
    Log4j配置详述
    Java-String-数据乱码
    javascript高级课程-3
    javascript高级课程-2
    javascript高级课程-1
    设计一个算法双链表删除重复
    设计一个算法将一个顺序表逆置
    w3c标准
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8151042.html
Copyright © 2020-2023  润新知