CodeForces 160B - Unlucky Ticket

CISP-PTE考前实操练习题 CISP-PTE考前学习练习题目,渗透测试功工程师 阅读详情

B. Unlucky Ticket
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 suchbijective correspondence between the digits of the first and the second half of the ticket, that either each digit of the first half turns outstrictly 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 > 1and 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 2n digits. Your task is to check whether it meets the unluckiness criterion.

Input

The first line contains an integer n (1 ≤ n ≤ 100). The second line contains a string that consists of 2n digits and defines your ticket.

Output

In the first line print "YES" if the ticket meets the unluckiness criterion. Otherwise, print "NO" (without the quotes).

Sample test(s)
input
2
2421
output
YES
input
2
0135
output
YES
input
2
3754
output
NO


================================


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n,flag1=1,flag2=1,a[111],b[111];char str[222];
    cin>>n;
    cin>>str;
    for(int i=0;i<n;i++) a[i]=str[i]-'0';
    for(int i=n;i<2*n;i++) b[i-n]=str[i]-'0';
    sort(a,a+n);
    sort(b,b+n);
    
    for(int i=0;i<n;i++)
    {
        if(a[i]<=b[i])
        {
            flag1=0;
            break;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]>=b[i])
        {
            flag2=0;
            break;
        }
    }
    //cout<<flag1<<" "<<flag2<<endl;
    if(!flag1&&!flag2) printf("NO\n");
    else printf("YES\n");
    return 0;
}


全面解读AI Infra:架构、生态与未来趋势 文章摘要 大模型时代下,AI基础设施(AI Infra)成为关键技术基建,涵盖从数据准备到模型服务的全栈技术体系。文章系统解构了AI Infra的四层架构(硬件资源层、资源管理调度层、开发框架层、平台工具层),并分析了全球AI Infra生态图谱,包括云计算巨头、芯片厂商等全栈服务商,以及中国特色的多元竞合格局。通过对比Data Infra与AI Infra的核心差异,指出AI Infra更关注智能应用的规模化与自动化。文章还探讨了从传统数据设施向AI基础设施的转型路径,强调自主可控、软硬协同等发展趋势,为 阅读详情

相关推荐

【Boost5】Boost变换器的输入电容

节点的电流有3个,一个是来自电源输入的,由于我们把Vin看成理想电源以及线路的电感的存在,它可以近似看作是恒定的电流源Iin,一个是流向输入电容Cin的电流Icin,另外一个节点是电感L电流IL。电容电流波形在整个开关周期内的平均值为0,充电和放电在一个周期中各占1/2,在图中充电部分面积和放电部分面积相等,那么在充电或放电的电荷量Q=I*t,从图中可以看出,在一个周期内电容电流变化量是ΔIL,那在电容在充电1/2T周期中电流的变化量是1/2ΔIL。输入电容上的ESR也会随着电流变化,影响输入电压的变化。

qq_43416206的博客 3348

B. Unlucky Ticket

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Each of you probably has your personal experience of riding publ

无知的我 1675

VMware Workstation Pro必备技巧:5分钟搞定Ubuntu虚拟机磁盘瘦身(附常见错误解决)

本文详细介绍了如何为VMware Workstation Pro中的Ubuntu虚拟机进行磁盘瘦身,解决.vmdk文件只增不减的问题。通过清理系统垃圾、使用零填充空闲空间,并利用vmware-toolbox-cmd或vmware-vdiskmanager工具进行压缩,可有效回收被无效占用的磁盘空间。文章还提供了常见错误解决方案和预防性维护建议,帮助用户高效管理虚拟机存储。

sea99的博客 296

Buy a Ticket CodeForces - 938D Dijkstra+思维

Musicians of a popular band “Flayer” have announced that they are going to “make their exit” with a world tour. Of course, they will visit Berland as well. There are n cities in Berland. People can tr...

why932346109的博客 298

10.2 构网型变流器引发的次同步振荡与宽频振荡问题:机理分析与抑制技术

随着构网型变流器在新型电力系统中的规模化部署,其作为电压源主动支撑电网的能力得到验证的同时,也引发了一系列前所未有的稳定性问题。传统的同步发电机主导的电力系统中,振荡模式主要集中于**低频区间**。然而,构网型变流器通过快速数字控制实现的虚拟同步、惯性响应等先进功能,其控制环路动态与电网阻抗、其他电力电子设备之间产生了复杂的交互作用。这种交互不仅可能诱发经典的**次同步振荡**,更可能催生频率范围从数赫兹到数百赫兹甚至上千赫兹的**宽频振荡**。

技术工作者 1306

扫地机器人视觉+IMU融合导航路径规划技术详解

本文介绍了基于视觉-惯性里程计(VIO)的扫地机器人自主导航系统。系统硬件由RGB摄像头、IMU传感器和编码器组成,软件架构采用分层设计,包括传感器数据采集层、数据融合层、SLAM定位层和路径规划层。核心技术包括:1)融合视觉特征提取(ORB算法)与IMU预积分的VIO;2)基于栅格地图的SLAM构建;3)结合A*全局规划和动态窗口法(DWA)局部避障的路径规划。文章提供了完整的Python实现代码,涵盖传感器数据融合、特征匹配和运动估计等关键功能模块。该系统实现了扫地机器人的精准定位和环境感知能力。

电脑管家 1463

字符串专项:CodeForces 235C

一道后缀自动机的算是模板题吧,可是我还是折腾了一个下午……总算对这个模板有了稍微深入的理解,debug了很久,也发现了不少的问题。现在算是基本会用后缀数组了。 #include #include #include #include using namespace std; const int maxn=2000010; const int sigma=26; int n,sz; st

bly 754

Claude Code vs Codex实战对比:哪个更适合你的Next.js项目?(含真实案例)

本文通过两个真实的Next.js项目案例,深度对比了Claude Code与Codex在UI实现和业务逻辑构建中的表现。Claude Code在代码质量、设计还原度和架构完整性方面优势明显,适合对可维护性要求高的生产级项目;而Codex则以快速响应和低成本见长,更适合原型开发或内部工具。文章提供了基于项目类型、团队能力和成本效益的详细选择策略。

weixin_29201859的博客 809

CodeForces-160B Unlucky Ticket

B. Unlucky Ticket time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Each of you probably has your personal experience of riding public transpor...

盈泽的博客 548

SAP Group Reporting入门指南(8)--业务操作

关于资产负债表类的匹配,系统预设了SGR01和SGR02两个方法,主要区别在于数据的来源范围,SGR01取自ACDOCA和ACDOCU,如果是0F类型的就会直接显示日记账分录(期间是000的除外,这类凭证是年结结转的,系统不再跨年追溯),如果是其他类型就显示合并分录。这里是我觉得SAP还需要优化的地方。基于ICMR的抵消任务中通常将抵销差异细分为交易差异、货币换算差异和其他差异,这在基于重分类抵消任务是无法实现的,基于重分类抵消只知道一个差异总额,很难从合并抵消凭证看出差异的来源,也没有审计线索可言。

bflyfish的博客 276

Open3d (C++) RANSAC拟合圆柱(详细过程版)

实现了一种基于RANSAC算法的圆柱拟合方法。

点云侠的博客 239

ural 1217. Unlucky Tickets

1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the first h...

anmob303090的博客 222

基于Python的股票K线图爬取与形态识别系统

本文详细介绍了一个基于Python的股票K线图爬取与形态识别系统。该系统通过网络爬虫技术获取股票历史数据,使用Matplotlib生成K线图,并应用卷积神经网络(CNN)对经典K线形态进行识别。文章详细阐述了数据采集、K线图生成、CNN模型构建与训练的完整流程,并提供了完整的代码实现。本研究为金融科技领域的毕业设计提供了有价值的参考方案。关键词:Python爬虫、K线图、卷积神经网络、形态识别、股票交易。

2201_76125261的博客 1033

CodeForces 160B Unlucky Ticket

B. Unlucky Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Each of you probably has your personal ex

曾经沧海难为水,除却巫山不是云 492

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Codeforces Round #111 (Div. 2) 160B. Unlucky Ticket(贪心)

B. Unlucky Ticket Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has anevennumber of di...

weixin_30482383的博客 144

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Codeforces Unlucky Ticket 题解

本题思路: 1 利用string保存数据,把string分成两半 2 由小到大排序 3 有小到大逐个比较,有一个不符合条件就可以结束循环了

靖空间 1208

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Codeforces Round #111 (Div. 2) B Unlucky Ticket (贪心)

题目: B. Unlucky Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Each of you probably has your pe

Notdeep__acm的专栏 768

Codeforces Round #481 (Div. 3) B. File Name

B. File Nametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou can not just take the file and send it. When Polycarp trying to send a file in the ...

qq_36603180的博客 372

CodeForces - 938D Buy a Ticket [Dijkstra]

CodeForces - 938D Buy a Ticket [Dijkstra]

ACTerminate的博客 989

Problem - 1326D2 - Codeforces(字符串hash)

Problem - 1326D2 - Codeforces 看的这篇博客的思路 题目大意:给定你一个长度为nnn的字符串,找出一个该字符串的一个前缀和一个后缀,使得这两个子串拼接成的字符串是一个回文串,求满足以上条件的最长回文串。 解题思路:首先是双指针匹配字符串的左右两端,如果值相等直接加入答案,如果不相等的话,那就从这个地方要找一个回文子串来重新构成回文串了。 当前情况下要不是从左边去匹配找到一个回文串,要不就是从右边去匹配找到一个回文串,具体的难点在于,如何优化查找回文串的复杂度。 这里用的方式

qq_53629286的博客 360

Codeforces 448B (字符串简单处理,读题)

水题。 也要考虑到特殊情况:如t比s长的情况,直接need tree,不用

Lostwinder的专栏 810

CodeForces 25BPhone numbers(简单的字符串模拟题目)

本题的题意如下:就是把每一串电话号码给分割开,分割为两个一组或者三个一组,所以笨渣渣心里想了好久好久,找出了一个比较笨的方法,就是对其进行分类讨论,看其对3取余后的结果是几,这样总共有三种可能性。 AC代码如下:这里写代码片#include<cstdio> #include<cstring> #include<iostream> using namespace std;int main() {

linlinsong—ACM界蒟水! 583

CF160D

题意:给你一个图,判断每条边是否在最小生成树MST上,不在输出none,如果在所有MST上就输出any,在某些MST上输出at least one; 分析:首先必须知道在最小生成树上的边的权值一定是等于任意最小生成树上的某条边的权值;那么我们按边的权值排序,每次同时加入权值相等的边 如果加入这条边之后形成loop那么这条边肯定不是最小生成树上的边,因为在此次加边之前,图上边的权值肯定是小于此次...

weixin_30767921的博客 193

Codeforces 1105B:Zuhair and Strings(字符串水题)

time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output Given a string sss of length nnn and integer k&nbsp;(1≤k≤n)k\ (1≤k≤n)k&nbsp;(1≤k≤n). ...

执念 832

codeforces 112APetya and Strings(字符串水题)

A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya loves presents. His mum b

2376

Codeforces Educational Codeforces Round 27 - B - Luba And The Ticket

B. Luba And The Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Luba has a ticket consisting of 6 di

vloai 410
上一篇: CodeForces 165C - Another Problem on Strings
下一篇: CodeForces 165B - Burning Midnight Oil(二分)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值