Codeforces-448【A数学函数ceil】【B思维】【D二分】

本文提供了三道编程竞赛题目的解答方案,包括奖励物品摆放问题、后缀结构转换问题及乘法表格查找问题,通过具体算法实现,展示了如何解决实际问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:点击打开链接

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

Bizon the Champion is called the Champion for a reason.

Bizon the Champion has recently got a present — a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has a1 first prize cups, a2 second prize cups and a3third prize cups. Besides, he has b1 first prize medals, b2 second prize medals and b3 third prize medals.

Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:

  • any shelf cannot contain both cups and medals at the same time;
  • no shelf can contain more than five cups;
  • no shelf can have more than ten medals.

Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.

Input

The first line contains integers a1a2 and a3 (0 ≤ a1, a2, a3 ≤ 100). The second line contains integers b1b2 and b3(0 ≤ b1, b2, b3 ≤ 100). The third line contains integer n (1 ≤ n ≤ 100).

The numbers in the lines are separated by single spaces.

Output

Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).

Examples
input
1 1 1
1 1 1
4
output
YES
input
1 1 3
2 3 4
2
output
YES
input
1 0 0
1 0 0
1
output
NO
题解:求出放置所有奖杯奖牌所需的架子数,其中有三个限制条件,注意一下就行了。又了解到一个数学函数,虽然是水题但是有点小收获

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
int a1,a2,a3,b1,b2,b3;
int main()
{
	while(~scanf("%d%d%d%d%d%d%d",&a1,&a2,&a3,&b1,&b2,&b3,&n))
	{
		int sum1=a1+a2+a3;
		int sum2=b1+b2+b3;
		int cnt1=sum1/5+(sum1%5==0?0:1);
		int cnt2=sum2/10+(sum2%10==0?0:1);
		if(cnt1+cnt2<=n)	puts("YES");
//		int cnt=ceil(sum1*1.0/5)+ceil(sum2*1.0/10); 数学函数doubl ceil(double x),返回不小于 x的最小整数 
//		if(cnt<=n)	puts("YES");
		else	puts("NO");	
	}
	return 0;
}

题目链接:点击打开链接

B. Suffix Structures
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.

At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.

Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.

Input

The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.

Output

In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word teven with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.

It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.

Examples
input
automaton
tomat
output
automaton
input
array
arary
output
array
input
both
hot
output
both
input
need
tree
output
need tree
Note

In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".


题解:如果串 s 包含串 t 的所有字母,而且这些字母在串 s 和串 t 中的排列顺序相同,输出 automaton;如果串 s 包含串 t 的所有字母,但排列顺序不同,进行判断,如果 lens==lent 输出 array,如果 lens>lent 输出 both,如果 lens < lent 输出 need tree;如果串 s 不存在包含串 t 的所有字母,输出 need tree。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
char s[110],t[110];
bool vis[110];
bool cmp1(string a,string b) // 检验串 a中是否存在串 b的所有字母,同时判断这些字母的排列顺序是否相同 
{
	memset(vis,0,sizeof(vis));
	int lena=a.length();
	int lenb=b.length();
	int last=0;
	for(int i=0;i<lenb;i++)
	{
		bool flag=0;
		for(int j=last;j<lena;j++)
		{
			if(!vis[j]&&a[j]==b[i])
			{
				last=j+1;
				vis[j]=1;
				flag=1;
				break;
			}
		}
		if(!flag)	return 0;
	}
	return 1;
}
bool cmp2(string a,string b) // 只检验串 a中是否含有串 b的所有字母,不进行这些字母排列顺序的判断 
{
	memset(vis,0,sizeof(vis));
	int lena=a.length();
	int lenb=b.length();
	for(int i=0;i<lenb;i++)
	{
		bool flag=0;
		for(int j=0;j<lena;j++)
		{
			if(!vis[j]&&a[j]==b[i])
			{
				vis[j]=1;
				flag=1;
				break;
			}
		}
		if(!flag)	return 0;
	}
	return 1;
}
int main()
{
	while(~scanf("%s%s",s,t))
	{
		int len1=strlen(s);
		int len2=strlen(t);
		if(len1<len2) // 此情况下,串 s必定不存在串 t的所有字母 
		{
			puts("need tree");
			continue;
		}
		if(cmp1(s,t))
		{
			puts("automaton");
		}
		else if(cmp2(s,t))
		{
			if(len1==len2)	puts("array");
			else	puts("both");
		}
		else	puts("need tree");
	}
	return 0;
}


题目链接:点击打开链接

D. Multiplication Table
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bizon the Champion isn't just charming, he also is very smart.

While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?

Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.

Input

The single line contains integers nm and k (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m).

Output

Print the k-th largest number in a n × m multiplication table.

Examples
input
2 2 2
output
2
input
2 3 4
output
3
input
1 10 5
output
5
Note

2 × 3 multiplication table looks like this:

1 2 3
2 4 6


#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n,m,k;
bool judge(LL mid)
{
	LL cnt=0;   //  cnt也要定义成 long long 型 ,这点WE了好多次 
	for(LL i=1;i<=n;i++)
	{
		cnt+=min(mid/i,m);   //第i行所有小于等于它的数的个数是min(mid/i,m)
	}
	return cnt>=k;
}
int main()
{
	while(~scanf("%lld %lld %lld",&n,&m,&k))
	{
		LL ans,left=1,right=n*m;
		while(left<=right)
		{
			LL mid=left+right>>1;
			if(judge(mid))
			{
				ans=mid;
				right=mid-1;
			}
			else
				left=mid+1;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值