题目链接:点击打开链接
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.
The first line contains integers a1, a2 and a3 (0 ≤ a1, a2, a3 ≤ 100). The second line contains integers b1, b2 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.
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).
1 1 1 1 1 1 4
YES
1 1 3 2 3 4 2
YES
1 0 0 1 0 0 1
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;
}
题目链接:点击打开链接
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.
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.
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.
automaton tomat
automaton
array arary
array
both hot
both
need tree
need tree
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;
}
题目链接:点击打开链接
#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;
}