您的位置:首页 > 其它

codeforces Round #256

2016-04-26 15:32 141 查看
昨晚上被叫去打cf,实在脑袋大,居然没有和他们撕逼。。。好吧,两天没睡觉还是能做出一题的。。。。

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

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


第一题,意思就是有a1,a2,a3个奖杯,b1,b2,b3个奖牌。n个架子。摆放规则是:一个架子只能摆奖杯或者是奖牌,一个架子最多能摆5个奖杯或者10个奖牌。问你能不能摆下

水题。

/*************************************************************************
> File Name: 1.cpp
> Author: Triose
> Mail: Triose@163.com
> Created Time: 2016/4/25 星期一 下午 1:22:15
************************************************************************/

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for((i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
int n, m;
int a1, a2, a3;
int b1, b2, b3;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
//	freopen("Out.txt", "w", stdout);
#endif
while(~sft(a1, a2, a3)) {
sft(b1, b2, b3);
sf(n);
int A = a1 + a2 + a3;
int B = b1 + b2 + b3;
n -= (A / 5 + (A % 5 == 0 ? 0 : 1));
n -= (B / 10 + (B % 10 == 0 ? 0 : 1));
if(n >= 0)
pfs("YES");
else
pfs("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".

对没错,这题我就wa在第一组数据。。。

一看题目,尼玛后缀自动机和后缀数组还有树。。。我tm好像都不会的样子。。。

不过后来一看题目也ok。给你两个字符串,让你把第一个通过某种变换变成第二个,如果只要使用后缀自动机(删除字母),就输出。。。如果只要使用后缀数组(换位置),就输出。。。,如果都要用输出both,都不要就输出need tree。。。

好吧,今早上起来写完的。。昨天实在懵逼。。。

写得挺乱的。。直接贴了吧

/*************************************************************************
> File Name: 2.cpp
> Author: Triose
> Mail: Triose@163.com
> Created Time: 2016/4/25 星期一 下午 1:40:31
************************************************************************/

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for((i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
int n, m;
int index1, index2;
int len1, len2;
#define N 110
char str1
;
char str2
;
int coun[30];
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
//	freopen("Out.txt", "w", stdout);
#endif
while(~sfs(str1)) {
sfs(str2);
index1 = false;
index2 = false;
len1 = strlen(str1);
len2 = strlen(str2);
index1 = (len1 == len2 ? false : true);
mem(coun, 0);
for(int i = 0; i < len1; i++) {
coun[str1[i] - 'a']++;
}
int j = 0;
for(j = 0; j < len2; j++) {
coun[str2[j] - 'a']--;
if(coun[str2[j] - 'a'] < 0) {
break;
}
}
if(j == len2) {
int i,k;
for(i = 0, k = 0; i < len1 && k < len2;) {
if(str1[i] == str2[k]) {
i++;k++;
}
else {
i++;
}
}
if(k != len2) {
index2 = true;
}
}
else {
index1 = false;
index2 = false;
}
if(index1 && index2) {
pfs("both");
}
else if(index1 && !index2) {
pfs("automaton");
}
else if(!index1 && index2) {
pfs("array");
}
else {
pfs("need tree");
}
//pfd(index1, index2);
}
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 ann × 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 n, m 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

A 2 × 3 multiplication table looks like this:
1 2 32 4 6


接下来第四题。第三题我还没看。。。n * m的乘法表,让你输出第k小的值。范围比较大没法存。千万注意用long long。

思想居然是二分。虽然我想到了(因为最小的肯定是1 * 1,最大的肯定是n * m),可是实在没法分啊。。(当时没想通,早上起来也没想通)。

易彰彪点化了我。。。这傻逼虽然晚上不睡觉但是做题还是挺可以。。

假如,我枚举一个数mid。那么是不是能算出比它小的数的个数和有多少个等于它的数?

既然能算出来,那是不是能判断这个数和k的大小?现在能不能二分?

的确有道理。。。。保存点啊什么的实在是没法做。。

二分我也写了好久。。途中错了好多次。。

贴代码吧。。

/*************************************************************************
> File Name: 4.cpp
> Author: Triose
> Mail: Triose@163.com
> Created Time: 2016/4/26 星期二 上午 2:54:30
************************************************************************/

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for((i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
LL n, m, k;
LL counter(LL mid, int & md) {
int i = 1;
LL ans = 0;
while(i <= n && mid / i) {
if(i * m < mid) {
ans += m;
}
else {
ans += (mid / i);
if(mid % i == 0) {
md++;
}
}
i++;
}
return ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
while(~scanf("%I64d%I64d%I64d", &n, &m, &k)) {
LL s = 1, e = n * m;
while(s <= e) {
LL mid = (s + e) >> 1;
int md = -1;
LL tmp = counter(mid, md);
if(k >= tmp - md && k <= tmp) {
pfI(mid);
break;
}
else if(k > tmp) {
s = mid + 1;
}
else if(k < tmp - md) {
e = mid - 1;
}
}
}
return 0;
}


另外两题再补上
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: