0
点赞
收藏
分享

微信扫一扫

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


题目链接:​​点击打开链接​​


A. Rewards



time limit per test



memory limit per test



input



output


Bizon the Champion is called the Champion for a reason.

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

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



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

The numbers in the lines are separated by single spaces.


Output



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



memory limit per test



input



output


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

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



s. The second line contains a non-empty word t. Words s and t


Output



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



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



memory limit per test



input



output



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

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?

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



nm and k (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m).



Output



k-th largest number in a n × m



Examples



input



2 2 2



output



2



input



2 3 4



output



3



input



1 10 5



output



5



Note



2 × 3



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;
}

举报

相关推荐

0 条评论