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",n-x);
 9     else printf("%d\n",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

723

output

YES2 1

input

1002510

output

YES0 10

input

1548

output

NO

input

996059425512557

output

YES1951 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\n");
11         cout << x << " " << (n-x*a)/b << endl;
12     }
13     else printf("NO\n");
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

2ivan 1 00123masha 1 00123

output

2masha 1 00123 ivan 1 00123 

input

3karl 2 612 12petr 1 12katya 1 612

output

3katya 1 612 petr 1 12 karl 1 612 

input

4ivan 3 123 123 456ivan 2 456 456ivan 8 789 3 23 6 56 9 89 2dasha 2 23 789

output

2dasha 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\n",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 }

原文地址:https://www.cnblogs.com/xingkongyihao/p/8151042.html

时间: 2024-08-29 22:47:51

Codeforces Round #451 (Div. 2) ABC的相关文章

Codeforces Round #247 (Div. 2) ABC

Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431 代码均已投放:https://github.com/illuz/WayToACM/tree/master/CodeForces/431 A - Black Square 题目地址 题意: Jury玩别踩白块,游戏中有四个区域,Jury点每个区域要消耗ai的卡路里,给出踩白块的序列,问要消耗多少卡路里. 分析: 模拟水题.. 代码: /* * Author: illuz

Codeforces Round #366 (Div. 2) ABC

Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 1 #I hate that I love that I hate it 2 n = int(raw_input()) 3 s = "" 4 a = ["I hate that ","I love that ", "I hate it","I love it"] 5 fo

Codeforces Round #312 (Div. 2) ABC题解

[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地.拉拉土地是一个非常美丽的国家,位于坐标线.拉拉土地是与著名的苹果树越来越随处可见. 拉拉土地恰好n苹果树.树数i位于位置xi和具有人工智能的苹果就可以了增长.阿姆鲁希望从苹果树收集苹果. AMR目前维持在X =0的位置.在开始的时候,他可以选择是否去左边或右边.他会在他的方向继续下去,直到他遇见一棵苹果树,他之前没有参观.他会采取所有的苹果,然后扭转他的方向,继续走这

Codeforces Round #429 (Div. 2)ABC

A: 题意:n个东西,k个朋友,全部给朋友,每个朋友不可以拿同样的,问是否可行 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 map<char ,int >ma; 5 int main(){ 6 int n,k; 7 cin>>n>>k; 8 string s; 9 cin>>s; 10 for(int i=0;i<n;i++){ 11 ma[s[i]]++; 12 if(ma[s

Codeforces Round #443 (Div. 2)ABC

A. Borya's Diagnosis It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Bor

Codeforces Round #450 (Div. 2)ABC

A. Find Extra One You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. Input The first line contains a single positive inte

【Codeforces Round #451 (Div. 2) D】Alarm Clock

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法+二分. 类似滑动窗口. 即左端点为l,右端点为r. 维护a[r]-a[l]+1总是小于等于m的就好. (大于m就右移左端点) 然后看看里面的数字个数是不是小于k; 不是的话让l..r中最右边那个数字删掉就好. ->链表优化一下即可. [代码] /* 1.Shoud it use long long ? 2.Have you ever test several sample(at least therr) yourself

Codeforces Round #451 (Div. 2) F Restoring the Expression

题意: 有一个a+b=c的等式,去掉两个符号,把三个数连在一起得到一个数 给出这个数,要求还原等式,length <= 1e6 三个数不能含有前导0,保证有解 解法: 铁头过题法,分类然后各种判断 我分了5种情况 0.开头字符为0, 那么结果一定是0+a=a的形式 然后4种情况 1.len(a) >= len(b) 且 len(c) == len(a) 2.len(a) <= len(b) 且 len(c) == len(b) 3.len(a) >= len(b) 且 len(c)

Codeforces Round #451 Div. 2 C D E

C.Phone Numbers 之前没有做过字典树--感觉这个题字典树也能做--就拿来练一练字典树--板子好多地方写的都不够好,还需要继续改-- emmm这个--卡了好久啊--不过好在还是debug出来了--orz 虽然是处理后缀的问题,但是只需要reverse一下就可以变成前缀问题了2333333,然后每一次的字符串都插进去,最后从叶子到根遍历输出就可以了-- 不过我好像--连叶子到根的遍历都写不好呜呜呜--ps:这里只是为了用trie而用trie--其实用map维护一下直接暴力求解就可以--