当前位置: 首页 > news >正文

AtCoder Beginner Contest 285解题报告

A - Edge Checker 2

Problem Statement

Determine if there is a segment that directly connects the points numbered a and b in the figure below.

Constraints

  • 1≤a<b≤15
  • a and b are integers.

Input

The input is given from Standard Input in the following format:

a b

Output

Print Yes  if there is a segment that directly connects the points numbered a and b; print No otherwise.


Sample Input 1

1 2

Sample Output 1

Yes

In the figure in the Problem Statement, there is a segment that directly connects the points numbered 1 and 2, so Yes should be printed.


Sample Input 2 

2 8

Sample Output 2

No

In the figure in the Problem Statement, there is no segment that directly connects the points numbered 2 and 8, so No should be printed.


Sample Input 3

14 15

Sample Output 3

No

AC Code:

#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int a, b;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> a >> b;
    if (b == a * 2 || b == a * 2 + 1)
        puts("Yes");
    else
        puts("No");
    return 0;
}

B - Longest Uncommon Prefix

思路:朴素方法

AC Code:

#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int n;
    string s;
    cin >> n >> s;
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i + j > n)
            {
                cout << j - 1 << "\n";
                break;
            }
            if (s[j - 1] == s[j + i - 1])
            {
                cout << j - 1 << "\n";
                break;
            }
        }
    }
    return 0;
}

 C - abc285_brutmhyhiizp

 

 AC Code:

// 简单模拟
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    string s;
    cin >> s;
    int l = s.size();
    long long res = 0, add = 26;
    for (int i = 1; i <= l - 1; i++)
    {
        res += add;
        add *= 26;
    }
    long long num = 0;
    for (int i = 0; i < l; i++)
    {
        num *= 26;
        num += (s[i] - 'A');
    }
    cout << res + num + 1;
    return 0;
}

F - Substring of Sorted String

AC Code:

#include<bits/stdc++.h>
using namespace std;

#define lowbit(x) x&(-x)

typedef long long ll;
const ll maxn=1e5+5;

int n,q;

char s[maxn];
int bit[30][maxn],sum[30],bit2[maxn];

void add(int a[maxn],int x,int c) {
	for(int i=x;i<=n;i+=lowbit(i)) a[i]+=c;
	return ;
}

int ask(int a[maxn],int x) {
	int res=0;
	for(int i=x;i>0;i-=lowbit(i)) res+=a[i];
	return res;
}

void add2(int x,int c) {
	for(int i=x;i<n;i+=lowbit(i)) bit2[i]+=c;
	return ;
}
 
int ask2(int x) {
	int res=0;
	for(int i=x;i>0;i-=lowbit(i)) res+=bit2[i];
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>s+1;
	for(int i=1;i<=n;i++) sum[s[i]-'a']++,add(bit[s[i]-'a'],i,1);
	for(int i=1;i<n;i++) if(s[i]<=s[i+1]) add2(i,1);
	cin>>q;
	for(int i=1,op;i<=q;i++) {
		cin>>op;
		if(op==1) {
			int x;char c;
			cin>>x>>c;
			sum[s[x]-'a']--,add(bit[s[x]-'a'],x,-1);
			if(x<n&&s[x]<=s[x+1]) add2(x,-1);
			if(x>1&&s[x-1]<=s[x]) add2(x-1,-1);
			s[x]=c;
			sum[s[x]-'a']++,add(bit[s[x]-'a'],x,1);
			if(x<n&&s[x]<=s[x+1]) add2(x,1);
			if(x>1&&s[x-1]<=s[x]) add2(x-1,1);
		}else {
			int l,r;
			cin>>l>>r;
			if(ask2(r-1)-ask2(l-1)!=r-l) {
				cout<<"No\n";
				continue;
			}
			int flag=0,tot=0;
			for(int j=0;j<26;j++) {
				int num=ask(bit[j],r)-ask(bit[j],l-1);
				tot+=num;
				if(!flag&&num==0) continue;
				if(!flag) flag=1;
				else {
					if(num<sum[j]&&tot!=r-l+1) {
						flag=-1;
						break;
					}
				}
			}
			if(flag==-1) cout<<"No\n";
			else cout<<"Yes\n";
		}
	}
	return 0;
}

相关文章:

  • 自从我学会了Jenkins的自动构建,我再也没有每次都打包上传到服务器然后发布Java服务了
  • 【目标检测】55、YOLOv8 | YOLOv5 团队 Ultralytics 再次出手,又实现了 SOTA
  • 【C++升级之路】第七篇:STL简介
  • k8s之ingress实战小栗子
  • 不会数学的程序员,只能走到初级开发工程师!
  • 基于贝叶斯算法的邮件过滤管理系统的设计和实现(Vue+SpringBoot)
  • 2023/1 寒假期间自学c++计划安排
  • 21 个 Java 核心技术
  • c语言实现扫雷(详细讲解)
  • 【C++】二叉树进阶OJ题
  • linux基本功系列之pwd命令实战
  • C/C++实现跨年表白烟花
  • TryHackMe-Minotaur‘s_Labyrinth
  • Elasticsearch连续剧之分词器
  • 【C语言】自定义类型
  • Apache Pulsar 2.1 重磅发布
  • JavaScript 无符号位移运算符 三个大于号 的使用方法
  • Javascript弹出层-初探
  • mysql_config not found
  • vue 配置sass、scss全局变量
  • 半理解系列--Promise的进化史
  • 使用阿里云发布分布式网站,开发时候应该注意什么?
  • 适配mpvue平台的的微信小程序日历组件mpvue-calendar
  • 验证码识别技术——15分钟带你突破各种复杂不定长验证码
  • 用jquery写贪吃蛇
  • 交换综合实验一
  • ​LeetCode解法汇总518. 零钱兑换 II
  • ​什么是bug?bug的源头在哪里?
  • #Js篇:单线程模式同步任务异步任务任务队列事件循环setTimeout() setInterval()
  • (003)SlickEdit Unity的补全
  • (3)STL算法之搜索
  • (C语言)输入一个序列,判断是否为奇偶交叉数
  • (动态规划)5. 最长回文子串 java解决
  • (二)linux使用docker容器运行mysql
  • (分布式缓存)Redis持久化
  • (附源码)ssm基于jsp的在线点餐系统 毕业设计 111016
  • (附源码)计算机毕业设计SSM疫情居家隔离服务系统
  • (转)Unity3DUnity3D在android下调试
  • ***通过什么方式***网吧
  • .NET MAUI学习笔记——2.构建第一个程序_初级篇
  • .NET委托:一个关于C#的睡前故事
  • /var/spool/postfix/maildrop 下有大量文件
  • :O)修改linux硬件时间
  • []利用定点式具实现:文件读取,完成不同进制之间的
  • [ACL2022] Text Smoothing: 一种在文本分类任务上的数据增强方法
  • [Android]常见的数据传递方式
  • [AutoSar]BSW_Memory_Stack_004 创建一个简单NV block并调试
  • [bzoj4240] 有趣的家庭菜园
  • [C/C++]数据结构 循环队列
  • [echarts] y轴不显示0
  • [elastic 8.x]java客户端连接elasticsearch与操作索引与文档
  • [fsevents@^2.1.2] optional install error: Package require os(darwin) not compatible with your platfo
  • [hive小技巧]同一份数据多种处理
  • [iOS]Win8下iTunes无法连接iPhone版本的解决方法
  • [NOIP2018 PJ T4]对称二叉树