Codeforces Round #451 (Div. 2) A-C题解

伤心总是难免的,明明是送分场,愣是掉了61分。

A. Rounding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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


问距离n最近的能被10整除的数是多少。

代码实现:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}

int main()
{
	ll n,i,j,k;
	while(~scanf("%lld",&n))
	{
		i=j=n;
		int ans1=0,ans2=0;
		for(k=0;;k++)
		{
			if(i%10==0)
			break;
			else
			{
				ans1++;
				i++;
			}
		}
		for(k=0;;k++)
		{
			if(j%10==0)
			break;
			else
			{
				j--;
				ans2++;
			}
		}
		if(ans1>=ans2)
		cout<<j<<endl;
		else
		cout<<i<<endl;
	}
	return 0;
}
B. Proper Nutrition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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


就是解一个二元一次方程,暴力1e8就ok,我少暴力了一个数量级。。。
代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}

int main()
{
	ll n,i,j,k,a,b,x,y;
	while(~scanf("%lld%lld%lld",&n,&a,&b))
	{
		for(i=0;i<=10000005;i++)
		{
			if(i*a>n)
			break;
			ll temp=(n-a*i)/b;
			if((n-a*i)%b==0)
			{
				printf("YES\n");
				printf("%lld %lld\n",i,temp);
				return 0;
			}
		}
		printf("NO\n");
	}
	return 0;
}

C. Phone Numbers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 
送分题不要,vector跑了一下,还是不要set直接跑了,两个迭代器,一次erase操作迭代器就跑偏了,怎么都回不来,对set迭代器还是玩不6.
代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}

map <string,int> mmp;
vector <string> s[100],ss[100];
string n_name,a,name[100];

int judge(string a,string b)
{
	int la=a.length()-1,lb=b.length()-1;
	if(la>lb)
	return 0;
	while(la>=0&&lb>=0)
	{
		if(a[la]!=b[lb])
		return 0;
		la--;
		lb--;
	}
	return 1;
}

int cmp(string a,string b)
{
	if(a.length()==b.length())
	return a<b;
	
	return a.length()<b.length();
}

int main()
{
	int n,i,j,k,m,l=0;
//	ios::sync_with_stdio(0);
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++)
	{
		cin>>n_name;
		if(mmp.count(n_name))
		{
			k=mmp[n_name];
			cin>>m;
			for(j=0;j<m;j++)
			{
				cin>>a;
				s[k].push_back(a);
			}
		}
		else
		{
			k=mmp[n_name]=l++;
			name[k]=n_name;
			cin>>m;
			for(j=0;j<m;j++)
			{
				cin>>a;
				s[k].push_back(a);
			}
		}
	}
	cout<<l<<endl;
	
/*	for(i=0;i<l;i++)
	{
		cout<<name[i]<<' ';
		for(j=0;j<s[i].size();j++)
		cout<<s[i][j]<<' ';
		
		cout<<endl;
	}*/
	for(i=0;i<l;i++)
	{
		sort(s[i].begin(),s[i].end(),cmp);
	}
	int temp;
	for(i=0;i<l;i++)
	{
		for(j=0;j<s[i].size();j++)
		{
			temp=0;
			for(k=j+1;k<s[i].size();k++)
			{
				if(j==k)
				continue;
				
				temp=judge(s[i][j],s[i][k]);
				
				if(temp)
				{
					break;
				}
			}
			if(!temp)
			ss[i].push_back(s[i][j]);
		}
		cout<<name[i]<<' ';
		cout<<ss[i].size()<<' ';
		for(j=0;j<ss[i].size();j++)
		cout<<ss[i][j]<<' ';
		cout<<endl;
	}
	return 0;
}


转载于:https://www.cnblogs.com/buzaijian/p/8849181.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值