Codeforces 898

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

把n/10之后四舍五入再*10

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long int LL;
int main()
{
    int n;
    while(cin>>n)
    {
        double x=1.0*n/10;
        x+=.5;
        n=(int)x;
        cout<<n*10<<endl;
    }
}

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

这个题被hack了一次!好气啊!

暴力解

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long int LL;
const int MAXL(10000000);
LL gcd_(LL m,LL n)
{
    if(n==0)
        return m;
    return gcd_(n,m%n);
}
int main()
{
    ios_base::sync_with_stdio(false);
    LL n,a,b;
    cin>>n>>a>>b;
    int flag=0;
    for(LL i=0; i*a<=n; i++)
    {
        if((n-i*a)>=0&&(n-i*a)<=MAXL&&(n-i*a)%b==0)
        {
            flag++;
            cout<<"YES"<<endl;
            cout<<i<<" "<<(n-i*a)/b<<endl;
            return 0;
        }
    }
    if(flag==0)
        cout<<"NO"<<endl;
}

898C 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

模拟啊模拟!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
map<string,vector<string> >mp;
bool cmp(string s1,string s2)
{
    return s1<s2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    string name,ss;
    for(int i=1; i<=n; i++)
    {
        cin>>name;
        int m;
        cin>>m;
        while(m--)
        {
            cin>>ss;
            reverse(ss.begin(),ss.end());//先翻转存入便于判断后缀
            mp[name].push_back(ss);
        }
    }
    cout<<mp.size()<<endl;
    map<string,vector<string> >::iterator it;
    for(it=mp.begin(); it!=mp.end(); it++)
    {
        string str[1000],ans[1000];
        cout<<it->first<<" ";
        vector<string>v=it->second;
        int len=v.size();
        for(int i=0; i<len; i++)
        {
            str[i]=v[i];
        }
        sort(str,str+len,cmp);
        int i,j,k=0;
        for(i=0; i<len; i++)
        {
            int temp,flag=0;
            for(j=i+1; j<len; j++)
            {
                temp=str[j].find(str[i]);
                if(temp==0)
                {
                    flag=1;
                    break;
                }
            }
            if(flag==0)
            {
                ans[++k]=str[i];
            }
        }
        cout<<k;
        for(int i=1; i<=k; i++)
        {
            reverse(ans[i].begin(),ans[i].end());
            cout<<" "<<ans[i];
        }
        cout<<endl;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值