AtCoder Beginner Contest 284解题报告(A-D)

news2024/10/6 8:40:07

A - Sequence of Strings

Problem Statement

You are given N strings S1​,S2​,…,SN​ in this order.

Print SN​,SN−1​,…,S1​ in this order.

Constraints

  • 1≤N≤10
  • N is an integer.
  • Si​ is a string of length between 1 and 10, inclusive, consisting of lowercase English letters, uppercase English letters, and digits.

Input

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

N
S1​
S2​
......
SN​

Output

Print N lines. The i-th (1≤i≤N) line should contain SN+1−i​.


Sample Input 1

3

Takahashi

Aoki

Snuke

Sample Output 1

Snuke

Aoki

Takahashi

We have N=3 .S1​= Takahashi,S2​= Aoki, and S3​= Snuke.

Thus, you should print SnukeAoki, and Takahashi in this order.


Sample Input 2

4

2023

Year

New
Happy

Sample Output 2

Happy

New

Year

2023

The given strings may contain digits.

AC Code:

逆序输出即可!

#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
stack<string> sta;
string s;
int n;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n;
    while (n--)
    {
        cin >> s;
        sta.push(s);
    }
    while (!sta.empty())
    {
        cout << sta.top() << '\n';
        sta.pop();
    }
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector <string> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = n - 1; i >= 0; i--) cout << s[i] << '\n';
    return 0;
}

B - Multi Test Cases

Problem Statement

In this problem, an input file contains multiple test cases.
You are first given an integer T. Solve the following problem for TT test cases.

  • We have N positive integers A1​,A2​,...,AN​. How many of them are odd?

Constraints

  • 1≤T≤100
  • 1≤N≤100
  • 1≤Ai​≤10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where test-i​ represents the i-th test case:

T
test1​
test2​
......
testT​

Each test case is in the following format:

N
A1......AN​

Output

Print T lines. The i-th line should contain the answer for the i-th test case.


Sample Input 1

4

3

1 2 3

2

20 23

10

6 10 4 1 5 9 8 6 5 1

1

1000000000

Sample Output 1

2

1

5

0

AC Code:

#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
const int N = 1e2 + 5;
int a[N], sum;
int t, n;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> t;
    while (t--)
    {
        sum = 0;
        cin >> n;
        for (int i = 0; i < n; i++)
            cin >> a[i];
        for (int i = 0; i < n; i++)
            if (a[i] & 1)
                sum++;
        cout << sum << '\n';
    }
    return 0;
}

C - Count Connected Components

Problem Statement

You are given a simple undirected graph with N vertices numbered 1 to N and M edges numbered 1 to M. Edge i connects vertex ui​ and vertex vi​.
Find the number of connected components in this graph.

Notes

A simple undirected graph is a graph that is simple and has undirected edges.
A graph is simple if and only if it has no self-loop or multi-edge.

A subgraph of a graph is a graph formed from some of the vertices and edges of that graph.
A graph is connected if and only if one can travel between every pair of vertices via edges.
A connected component is a connected subgraph that is not part of any larger connected subgraph.

Constraints

  • 1≤N≤100
  • The given graph is simple.
  • All values in the input are integers.

Input

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

N M
u1 v1
u2 v2
......
uM vM

Output

Print the answer.


Sample Input 1

5 3
1 2
1 3
4 5

Sample Output 1

2

The given graph contains the following two connected components:

  • a subgraph formed from vertices 1, 2, 3, and edges 1, 2;
  • a subgraph formed from vertices 4, 5, and edge 3.


Sample Input 2

5 0

Sample Output 2

5

Sample Input 3

4 6
1 2
1 3
1 4
2 3
2 4
3 4

Sample Output 3

1

连通块的数量

AC Code:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e5 + 10;

int n, m, p[N];

int find(int x)
{
    if (p[x] != x)
        p[x] = find(p[x]);
    return p[x];
}
signed main()
{
    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        p[i] = i;

    while (m--)
    {
        int u, v;
        cin >> u >> v;
        u = find(u), v = find(v);
        if (u != v)
            p[u] = v;
    }

    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans += find(i) == i;

    cout << ans << '\n';
}

D - Happy New Year 2023

Problem Statement

There is an integer N. It is known that N can be represented as N=p^2*q using two different prime numbers p and q. Find p and q.You have T test cases to solve.


Input

The input is given from Standard Input in the following format, where test-i​ represents the i-th test case:​

T
test1
test2
test3
......
testT

1<=T<=10.

1<=N<=9*10^18.

Each test case is in the following format:

N

Output

Print T lines.


Sample Input 1

3
2023
63
1059872604593911

Sample Output 1

17 7
3 7
104149 97711

AC Code:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e6 + 10;
int n, cnt, primes[N];
bool st[N];
void get_primes()
{
    for (int i = 2; i < 3e6; i++)
    {
        if (!st[i])
            primes[cnt++] = i;
        for (int j = 0; primes[j] * i < 3e6; j++)
        {
            st[primes[j] * i] = true;
            if (i % primes[j] == 0)
                break;
        }
    }
}
void solve()
{
    cin >> n;
    for (int i = 0; i < cnt; i++)
    {
        if (n % (primes[i] * primes[i]) == 0)
        {
            cout << primes[i] << " " << n / (primes[i] * primes[i]) << '\n';
            return;
        }
        if (n % primes[i] == 0)
        {
            int num = n / primes[i];
            int x = (int)sqrt(num);
            cout << x << " " << primes[i] << '\n';
            return;
        }
    }
}
signed main()
{
    get_primes();
    st[1] = 1;
    int T;
    cin >> T;
    while (T--)
        solve();
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/165413.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【Redis】Redis实现分布式锁

【Redis】Redis实现分布式锁 文章目录【Redis】Redis实现分布式锁1. 分布式锁概念2. 为什么要实现分布式锁2.1 并发安全问题3. 分布式锁的实现方案3.1 Redis实现分布式锁3.1.1 定义分布锁接口和类3.1.2 编写lua脚本3.1.3 使用线程锁3.1.4 总结在实现分布式锁之前&#xff0c;首…

aardio - 升级bindConfig函数,支持多属性和多子组件

一、需求分析 aardio的 winform.bindConfig() 函数&#xff0c;绑定后&#xff0c;一个组件&#xff0c;只能保存一个属性。 有时候需要同时保存多个属性&#xff0c;比如一个comobox组件&#xff0c;需要保存项目列表&#xff0c;同时保存当前选中的项目索引。当前这个bindC…

代码随想录算法训练营第十八天二叉树 java : .106 从中序与后序遍历序列构造二叉树113. 路径总和ii 112 路径总和 513.找树左下角的值

文章目录前言LeetCode 513.找树左下角的值题目讲解思路那么如何找最左边的呢&#xff1f;Leetcode 112 路径总和题目讲解LeetCode 113. 路径总和ii题目讲解Leetcode 106 从中序与后序遍历序列构造二叉树题目讲解前言 人的不幸在于他们不想走自己的那条路&#xff0c;总想走别人…

大数据必学Java基础(一百二十四):Maven的常见插件

文章目录 Maven的常见插件 一、编辑器插件 二、资源拷贝插件 三、tomcat插件 Maven的常见插件

Dubbo 服务暴露

Dubbo 服务暴露 1. 服务暴露时序图 2. 源码分析 DubboBootstrap.exportServices 从配置管理器中获取到所有的ServiceConfig实例&#xff0c;遍历&#xff0c;然后一个一个的暴露。 ServiceConfig.export 如果DubboBootstrap为空&#xff0c;也就没有初始化&#xff0c;就初…

猴子都能看懂的噪声(noise)专题

背景 除了生成各种奇形怪状与自然景观&#xff0c;噪声也有其他美妙的用途&#xff01; 工作原因&#xff0c;经常接触与噪声相关的画面效果&#xff08;火焰啊&#xff0c;画面扰动啊之类的&#xff09;&#xff0c;做的时候一知半解&#xff0c;傻傻分不清楚各种形态的nois…

Java文件:XWPFDocument导出Word文档

文章目录一、前言二、基本的概念三、Maven依赖(JAR)四、Word模板1.正文段落2.正文表格3.页眉4.页脚五、XWPFDocument的使用5.4导出Word文档1.word模板2.PdfTest测试类3.ISystemFileService接口4.SystemFileServiceImpl实现类5.结果六、遇到问题5.1输出为word的时候换行符无效一…

NR5G基础概念扫盲

文章目录前言BWP未完待续前言 随着人工智能、万物互联时代的到来&#xff0c;人类社会进入到一个新的阶段。新兴的科技产业对信息社会基础设施提出了更高的要求&#xff0c;对低时延、大带宽、高流量的需求&#xff0c;催生了5G技术&#xff0c;并推动其蓬勃发展。通信&#x…

【深入浅出XML】包装纯粹信息的标记语言

XMLXML的定义和概述&#x1f3b6;XML的定义&#x1f3b6;XML的最好描述&#x1f3b6;HTML和XML的重要区别&#x1f3b6;XML的文档结构&#x1f3b6;其他一些标记XML和优势&#x1f3b6;XML的优势XML解析&#x1f3b6;DOM解析❔解析测试&#x1f91e;解析步骤&#x1f91e;案例测…

在Windows部署Java的Jar包

背景 使用 Java 编写了一些有用的工具&#xff0c;因为不方便部署到服务器上&#xff0c;所以需要把 Java 生成的 jar 包在本地 Windows 上部署。 查阅了几种部署方式&#xff0c;认为通过 winsw 进行部署最方便。 安装 winsw 进入 winsw 的下载页面&#xff0c;下载 sampl…

【ROS2 入门】ROS 2 参数服务器(parameters)概述

大家好&#xff0c;我是虎哥&#xff0c;从今天开始&#xff0c;我将花一段时间&#xff0c;开始将自己从ROS1切换到ROS2&#xff0c;在上一篇中&#xff0c;我们一起了解ROS 2中Topic&#xff0c; 这一篇&#xff0c;我们主要会围绕ROS中另外一个重要的概念“Parameters ”&am…

图的拓扑排序(AOV网络)

文章目录拓扑排序概念实现邻接表(队列)邻接矩阵(栈)总结源代码邻接表邻接矩阵拓扑排序 概念 拓扑排序是对有向无环图的顶点的一种排序. AOV网络 : 在有向图中, 用顶点表示活动或者任务, 弧表示活动或者任务间的优先关系, 则此有向图称为用顶点表示活动的网络(Activity On Ve…

小程序介绍和注册安装

小程序介绍和注册安装微信小程序介绍小程序特点其它平台小程序注册微信小程序开发帐号获取appidappid简介微信开发者工具安装创建一个小程序项目核心步骤微信开发者工具构成微信小程序介绍 简短定义&#xff1a;微信小程序是运行在微信APP中的一个程序。 常见小程序 行程码拼…

UDS诊断系列介绍11-3E服务

本文框架1. 系列介绍1.1 3E服务概述2. 3E服务请求与应答2.1 3E服务请求2.2 3E服务正响应2.3 3E服务否定响应3. Autosar系列文章快速链接1. 系列介绍 UDS&#xff08;Unified Diagnostic Services&#xff09;协议&#xff0c;即统一的诊断服务&#xff0c;是面向整车所有ECU的…

# 【笔记】大话设计模式21-23

【笔记】大话设计模式21-23 文章目录【笔记】大话设计模式21-23单例模式21.1 Example21.2 定义21.3 Show me the code一般单例代码(**懒汉模式**)静态初始化&#xff08;**饿汉模式**&#xff09;21.4 总结22 桥接模式22.1 Example22.2 定义22.3 Show me the code22.4 总结23 命…

Code for VeLO 1: Training Versatile Learned Optimizers by Scaling Up

Code for VeLO 1: Training Versatile Learned Optimizers by Scaling Up 这篇文章将介绍一下怎么用VeLO进行训练。 这篇文章基于https://colab.research.google.com/drive/1-ms12IypE-EdDSNjhFMdRdBbMnH94zpH#scrollToRQBACAPQZyB-&#xff0c;将介绍使用learned optimizer in…

入门力扣自学笔记230 C++ (题目编号:2293)

2293. 极大极小游戏 题目&#xff1a; 给你一个下标从 0 开始的整数数组 nums &#xff0c;其长度是 2 的幂。 对 nums 执行下述算法&#xff1a; 设 n 等于 nums 的长度&#xff0c;如果 n 1 &#xff0c;终止 算法过程。否则&#xff0c;创建 一个新的整数数组 newNums …

【Python百日进阶-数据分析】Day226 - plotly的仪表盘go.Indicator()

文章目录一、语法二、参数三、返回值四、实例4.1 Bullet Charts子弹图4.1.1 基本子弹图4.1.2 添加步骤和阈值4.1.3 自定义子弹4.1.4 多子弹4.2 径向仪表图4.2.1 基本仪表4.2.2 添加步骤、阈值和增量4.2.3 自定义仪表图4.3 组合仪表图4.3.1 组合仪表图4.3.2 单角量规图4.3.3 子弹…

Android 深入系统完全讲解(19)

技术的学习关键点 是什么&#xff1f;思路。 而我这里分享一个学习的经典路线&#xff0c;先厘清总框架&#xff0c;找到思路&#xff0c;然后再逐步击破。 这里关于音视频的就是&#xff1a; 总体分为几部分&#xff1a; 1 绘制 2 编解码格式 3 Android 平台的 FFmpeg 开源移…

Compressed Sensing——从零开始压缩感知

Problem 考虑一个线性方程组求解问题&#xff1a; Axb(1)A x b \tag{1}Axb(1) 其中&#xff0c;A∈RmnA \in\mathbb R^{m\times n}A∈Rmn&#xff0c;x∈Rn1x \in\mathbb R^{n\times 1}x∈Rn1&#xff0c;b∈Rm1b \in\mathbb R^{m\times 1}b∈Rm1且m≪nm \ll nm≪n 这是一个…