[八中测试]AtCoder ABC093

本文详细解析了AtCoder ABC093竞赛中的四道题目,包括'A'题的字符串排列验证,'B'题的大小整数筛选,'C'题的同值整数最少操作次数,以及'E'题的糖果分配问题。每道题目都提供了问题陈述、约束条件、输入输出示例以及最优解法的思路和AC代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A - abc of ABC

Problem Statement

You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc.

Constraints

|S|=3
S consists of a, b and c.
Input
Input is given from Standard Input in the following format:

S

Output

If S can be obtained by permuting abc, print Yes; otherwise, print No.

Sample Input 1

bac

Sample Output 1

Yes

Swapping the first and second characters in bac results in abc.

Sample Input 2

bab

Sample Output 2

No

Sample Input 3

abc

Sample Output 3

Yes

Sample Input 4

aaa

Sample Output 4

No

【解析】

第一题应该很好理解,也应该很快可以完成,就是一个暴力判定,就完。

AC代码:

#include<cstdio>
#define N 6
char s[N];
bool f[N];
int main()
{
    scanf("%s",s);
    for(int i=0;i<3;i++)
    f[int(s[i]-97)]=1;
    if(f[0]&&f[1]&&f[2]) printf("Yes\n");
    else printf("No\n");
}
----------------------------------------------------------------

B - Small and Large Integers

Problem Statement

Print all the integers that satisfies the following in ascending order:

Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

Constraints

1≤A≤B≤109
1≤K≤100
All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print all the integers that satisfies the condition above in ascending order.

Sample Input 1

3 8 2

Sample Output 1

3
4
7
8

3 is the first smallest integer among the integers between 3 and 8.
4 is the second smallest integer among the integers between 3 and 8.
7 is the second largest integer among the integers between 3 and 8.
8 is the first largest integer among the integers between 3 and 8.

Sample Input 2

4 8 3

Sample Output 2

4
5
6
7
8

Sample Input 3

2 9 100

Sample Output 3

2
3
4
5
6
7
8
9

【解析】

这道题应该也很容易完成,就一个顺序输出和逆序输出的问题吧。
AC代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int A,B,K;
int cnt=0;
int a[106];
int main()
{
    scanf("%d %d %d",&A,&B,&K);
    for(int i=A;i<=min(A+K-1,B);i++)
    {
    printf("%d\n",i);
    }
    for(int i=B;i>=max(B-K+1,A+K);i--)
    {
        a[++cnt]=i;
    }
    sort(a+1,a+1+cnt);
    for(int i=1;i<=cnt;i++)
    printf("%d\n",a[i]);
}
----------------------------------------------------------------

C - Same Integers

Problem Statement

You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:

Choose two among A, B and C, then increase both by 1.
Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Constraints

0≤A,B,C≤50
All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the minimum number of operations required to make A, B and C all equal.

Sample Input 1

2 5 4

Sample Output 1

2

We can make A, B and C all equal by the following operations:

Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.
Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.

Sample Input 2

2 6 3

Sample Output 2

5

Sample Input 3

31 41 5

Sample Output 3

23

【解析】

这道题看看数据,暴力模拟应该是没有问题的,所以,何乐而不为呢?
方法一:【暴力模拟】

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[5];
int cnt=0;
int main()
{
    for(int i=1;i<=3;i++)
        scanf("%d",&a[i]);
    int cnt=0;
    int f=1;
    while(f)
    {
        if(a[1]==a[2]&&a[2]==a[3]) break;
        sort(a+1,a+1+3);
        while(a[1]+2<=a[3])a[1]+=2,cnt++;
        if(a[1]==a[2]&&a[2]==a[3]) break;
        while(a[2]+2<=a[3])a[2]+=2,cnt++;
        if(a[1]==a[2]&&a[2]==a[3]) break;
        if(a[2]==a[3]&&a[1]!=a[2]) a[1]+=2,a[2]+=1,a[3]+=1,cnt+=2;\
        if(a[1]==a[2]&&a[2]==a[3]) break;
        if((a[1]+1<=a[3]&&a[2]+1<=a[3]))a[1]+=1,a[2]+=1,cnt++;
    }
    printf("%d",cnt);
}

当然,还有一种数学方法,可以进行探究。

----------------------------------------------------------------

E - Tozan and Gezan

Problem Statement

You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is Ai, and the i-th element in B is Bi.

Tozan and Gezan repeats the following sequence of operations:

If A and B are equal sequences, terminate the process.
Otherwise, first Tozan chooses a positive element in A and decrease it by 1.
Then, Gezan chooses a positive element in B and decrease it by 1.
Then, give one candy to Takahashi, their pet.
Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally.

Constraints

1≤N≤2×105
0≤Ai,Bi≤109(1≤i≤N)
The sums of the elements in A and B are equal.
All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A1 B1
:
AN BN

Output

Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.

Sample Input 1

2
1 2
3 2

Sample Output 1

2

When both Tozan and Gezan perform the operations optimally, the process will proceed as follows:

Tozan decreases A1 by 1.
Gezan decreases B1 by 1.
One candy is given to Takahashi.
Tozan decreases A2 by 1.
Gezan decreases B1 by 1.
One candy is given to Takahashi.
As A and B are equal, the process is terminated.

Sample Input 2

3
8 3
0 1
4 8

Sample Output 2

9

Sample Input 3

1
1 1

Sample Output 3

0

【解析】

题意:给出A B 2个序列,他们的序列总和相同,2个人T和G,双方轮流选择序列中一个正整数,进行减一,

T想尽可能的使步数大,G想尽可能的使步数小,计算使得2个序列完全相同的步数

当所有的Bi=Ai的时候输出0

G:为了使得步数尽可能的小,当Bi>Ai的时候只要减少Bi即可,当Bi<Ai的时候,不动即可

T:为了使得步数尽可能的大,当Bi>Ai的时候,Ai必定最后为0,当Bi<Ai的时候,记录最小的Bi为Bk(k为符合条件的最小值的下标),让G误以为所有的A都是要趋向于Bk,实则是为了变为0,除非T不得不移动Ak(也就是其他的A都为0)

综上得:结果为sum-minb
AC代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x7fffffff
#define N 200007
int n;
long long cnt,a,b,minb=INF;
bool f=0;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld %lld",&a,&b);
        cnt+=b;
        if(b<a&&minb>b)
        minb=b;
        if(b!=a) f=1; 
    }
    if(f)printf("%lld\n",cnt-minb);
    else printf("0\n");
}
关于 AtCoder Beginner Contest 387 的信息如下: ### 关于 AtCoder Beginner Contest 387 AtCoder Beginner Contest (ABC) 是一项面向编程爱好者的定期在线竞赛活动。对于 ABC387,该赛事通常会在周末举行,并持续大约100分钟,在此期间参赛者需解决一系列算法挑战问题。 #### 比赛详情 - **举办平台**: AtCoder Online Judge System[^2] - **比赛时间长度**: 大约为1小时40分钟 - **难度级别**: 初学者友好型,适合那些刚开始接触竞争性程序设计的人群参与 - **题目数量**: 一般情况下会提供四到六道不同难度级别的题目供选手解答 #### 题目概览 虽然具体细节可能因官方发布而有所变化,但可以预期的是,这些题目将会覆盖基础的数据结构、字符串处理以及简单图论等方面的知识点。每一道题目的描述都会清晰给出输入输出格式说明及样例测试数据以便理解需求并验证解决方案的有效性。 为了获取最准确的比赛时间和确切的题目列表,请访问 [AtCoder 官方网站](https://atcoder.jp/) 并查看最新的公告板或直接导航至对应编号的具体页面来获得更新的信息。 ```python import requests from bs4 import BeautifulSoup def get_contest_info(contest_id): url = f"https://atcoder.jp/contests/{contest_id}" response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') title_element = soup.find('title') problem_list_elements = soup.select('.panel.panel-default a[href^="/contests/{}/tasks"]'.format(contest_id)) contest_title = title_element.string.strip() if title_element else "Contest Title Not Found" problems = [element['href'].split('/')[-1] for element in problem_list_elements] return { "name": contest_title, "problems": problems } else: raise Exception(f"Failed to fetch data from {url}") abc_387_details = get_contest_info("abc387") print(abc_387_details) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值