CF160B.Unlucky Ticket
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches the sum of digits in its second half.
But of course, not every ticket can be lucky. Far from it! Moreover, sometimes one look at a ticket can be enough to say right away that the ticket is not lucky. So, let's consider the following unluckiness criterion that can definitely determine an unlucky ticket. We'll say that a ticket is definitely unlucky if each digit from the first half corresponds to some digit from the second half so that each digit from the first half is strictly less than the corresponding digit from the second one or each digit from the first half is strictly more than the corresponding digit from the second one. Each digit should be used exactly once in the comparisons. In other words, there is such bijective correspondence between the digits of the first and the second half of the ticket, that either each digit of the first half turns out strictly less than the corresponding digit of the second half or each digit of the first half turns out strictly more than the corresponding digit from the second half.
For example, ticket 2421 meets the following unluckiness criterion and will not be considered lucky (the sought correspondence is 2 > 1 and 4 > 2), ticket 0135 also meets the criterion (the sought correspondence is 0 < 3 and 1 < 5), and ticket 3754 does not meet the criterion.
You have a ticket in your hands, it contains 2_n_ digits. Your task is to check whether it meets the unluckiness criterion.
各位可能都有过乘坐公共交通工具并购买车票的经历。当一个人购买了一张车票(传统上该车票具有偶数位数字)后,他通常会检查这张车票是否为“幸运票”。我们来回顾一下:若一张车票前一半数字之和等于后一半数字之和,则称其为幸运票。
但显然,并非每张车票都可能是幸运的——远非如此!此外,有时仅需一眼观察一张车票,便可立即断定它绝非幸运票。因此,我们考虑如下一种确定性不幸运判据(definitely unlucky criterion),该判据可绝对判定一张车票为不幸运票。我们称一张车票为确定性不幸运票,如果存在一种方式,使得前一半的每一位数字均与后一半的某一位数字一一对应(即构成双射),并且满足以下两种情形之一:
- 前一半的每一位数字严格小于其对应的后一半数字;
- 或前一半的每一位数字严格大于其对应的后一半数字。
在上述比较中,前一半与后一半的每一位数字均须被使用且仅使用一次。换言之,存在前半部分数字与后半部分数字之间的一个双射对应关系,使得要么前半部分所有数字均严格小于其对应后半部分数字,要么前半部分所有数字均严格大于其对应后半部分数字。
例如,车票 2421 满足该不幸运判据,因而不会被视为幸运票(所求对应关系为 2>1 且 4>2);车票 0135 同样满足该判据(所求对应关系为 0<3 且 1<5);而车票 3754 则不满足该判据。
你手中持有一张含有 2n 位数字的车票。你的任务是判断它是否满足该不幸运判据。
输入格式
The first line contains an integer n (1 ≤ n ≤ 100). The second line contains a string that consists of 2_n_ digits and defines your ticket.
第一行包含一个整数 n(1≤n≤100)。第二行包含一个由 2n 个数字组成的字符串,表示你的车票。
输出格式
In the first line print "YES" if the ticket meets the unluckiness criterion. Otherwise, print "NO" (without the quotes).
如果车票满足不幸运条件,则在第一行输出 “YES”;否则输出 “NO”(不带引号)。
输入输出样例
输入#1
2 2421
输出#1
YES
输入#2
2 0135
输出#2
YES
输入#3
2 3754
输出#3
NO
输入解题思路,AI测评打分。不知道怎么写?