AtCoder abc 355

https://atcoder.jp/contests/abc355

A:

问题陈述:

Takahashi’s cake has been eaten by someone. There are three suspects: person 1 1 1, person 2 2 2, and person 3 3 3.

There are two witnesses, Ringo and Snuke. Ringo remembers that person A A A is not the culprit, and Snuke remembers that person B B B is not the culprit.

Determine if the culprit can be uniquely identified based on the memories of the two witnesses. If the culprit can be identified, print the person’s number.

分析:

在1,2,3这三个数中,输入两个值,若这两个值相同,输出-1,若这两个数不相等,输出除这两个数之外的第三个数的值。(因为本题中1,2,3,是固定数值,因此我们也可以输出(6-a-b)或者输出a^b)

代码1:

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

map<int,int> s;
int main()
{
	int a,b;
	cin >> a;
	s[a]=1;
	cin >> b;
	s[b]=1;
	if(a==b)
	cout << -1;
	else
	for(int i=1;i<=3;i++)
	{
		if(s[i]!=1)
		cout << i ;
	}
	return 0;
}

代码2:

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

int main()
{
	int a,b;
	cin >> a >> b;
	if(a==b)
	cout << -1;
	else
	cout << 6-a-b;
    //cout << a^b;
	return 0;
}

B:

问题陈述

You are given a sequence A = ( A 1 , A 2 , … , A N ) A=(A_1,A_2,\dots,A_N) A=(A1,A2,,AN) of length N N N and a sequence B = ( B 1 , B 2 , … , B M ) B=(B_1,B_2,\dots,B_M) B=(B1,B2,,BM) of length M M M. Here, all elements of A A A and B B B are pairwise distinct. Determine whether the sequence C = ( C 1 , C 2 , … , C N + M ) C=(C_1,C_2,\dots,C_{N+M}) C=(C1,C2,,CN+M) formed by sorting all elements of A A A and B B B in ascending order contains two consecutive elements appearing in A A A.

分析:

输入A,B两个数组,分别对其进行排序,对aA,B数组循环,判断是否出现A中两个连续元素。

代码实现:

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

int a[110],b[110];

int main()
{
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i]; 
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=m;i++)
	{
		cin >> b[i];
	}
	sort(b+1,b+m+1);
	int i=1,j=1,flag=0;
	while(i<=n&&j<=m)
	{
		if(a[i]<b[j])
		{
			i++;
			flag++;
			if(flag==2)
			{
				cout << "Yes";
				return 0;
			}
		}
		else
		{
			j++;
			flag=0;
		}
	}
	while(i<=n) {
		i++;
		flag++;
		if(flag==2)
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

C:

问题描述:

There is an N × N N \times N N×N grid, where the cell at the i i i-th row from the top and the j j j-th column from the left contains the integer N × ( i − 1 ) + j N \times (i-1) + j N×(i1)+j.

Over T T T turns, integers will be announced. On Turn i i i, the integer A i A_i Ai is announced, and the cell containing A i A_i Ai is marked. Determine the turn on which Bingo is achieved for the first time. If Bingo is not achieved within T T T turns, print -1.

Here, achieving Bingo means satisfying at least one of the following conditions:

  • There exists a row in which all N N N cells are marked.
  • There exists a column in which all N N N cells are marked.
  • There exists a diagonal line (from top-left to bottom-right or from top-right to bottom-left) in which all N N N cells are marked.

分析:

首先,我们需要按照输入数据构造一个N*N的表格,表格中的数据为1-N,分别定义行数组,列数组,和对应的两个对角线数组,初定义均为零。

读入每个回合输入的值对应的每行每列,及对角线数组的值加一,判断是否有数组的值达到N,如果有,则输出此时的 i 值,直接返回,否则继续进行,直到输出-1。

代码实现:

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

const int N = 2*1e3+10;
int a[N][N];
int t[N*N];
int r[N]={0},l[N]={0},c[N]={0};
int main()
{
	int n,T;
	cin >> n >> T;
	for(int i=1,k=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++) 
		a[i][j]=k++;
	}
	for(int i=1;i<=T;i++)
	{
		cin >> t[i];
        t[i]--;//对数据进行处理
		int x=t[i]/n;
		int y=t[i]%n; //判断行和列
		if(x==y) c[1]++; 
		if(x+y==n-1) c[2]++; //判断是否在对角线上
		if(++r[x]==n||++l[y]==n||c[1]==n||c[2]==n)
		{
			cout << i;
			return 0;
		}
	} 
	cout << -1;
	return 0;
}

D:

问题描述:

You are given N N N intervals of real numbers. The i i i-th ( 1 ≤ i ≤ N ) (1 \leq i \leq N) (1iN) interval is [ l i , r i ] [l_i, r_i] [li,ri]. Find the number of pairs ( i , j )   ( 1 ≤ i < j ≤ N ) (i, j)\,(1 \leq i < j \leq N) (i,j)(1i<jN) such that the i i i-th and j j j-th intervals intersect.

分析:

本题中我们要找出有相交部分的区间对数,根据数据范围来看,暴力循环显然不可行,要找出有相交部分的区间对比较麻烦,所以,我们可以选择找到不相交区间的对数再用总区间对数减去该值。
要找到不相交的区间堆,我们可以分别对左区间和右区间进行排序,然后将利用双指针遍历,计算出不相交区间对的数量。

代码实现:

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

const int N = 5*1e5+10;
int l[N],r[N];

int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> l[i] >> r[i];
    }
    sort(l,l+n);
    sort(r,r+n);
    long long int ans=(long long)(n-1)*n/2; //一定要开long long 
    for(int i=0,j=0;i<n;i++)
    {
        while(j<n&&r[j]<l[i])
        {
            j++;
        }
        ans-=j;
    }
    cout << ans ;
    return 0;
}

24/5/27

  • 24
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: atcoder beginner contest 235 是一场由 AtCoder 组织的初学者比赛,旨在为初学者提供一个锻炼自己编程能力的平台。比赛通常包括多个问题,参赛者需要在规定时间内解决这些问题。比赛难度逐渐增加,从而帮助参赛者提高自己的编程技能。 ### 回答2: ATCoder Beginner Contest 235(简称ABC 235)是一项由ATCoder举办的编程竞赛。该比赛旨在为初学者提供一个机会展示他们的编程技巧和解决问题的能力。 ABC 235通常由4个问题组成,题目难度递增。参赛者需要在规定的时间内使用编程语言解决这些问题。这些问题通常涵盖了各种编程相关的主题,例如数学问题、字符串处理、排序和搜索算法等。 在比赛开始前,参赛者将获得一份题目说明文档和输入样例。他们需要根据题目要求编写程序,处理给定的输入数据,并生成相应的输出。比赛时间一般为2-3小时,参赛者需要尽可能快速且准确地解决问题。 评判将根据参赛者的程序输出与预期结果的一致性进行。参赛者可以在比赛过程中提交多次解答,但只有第一次正确答案会被记入最终的成绩。 ABC 235不仅提供了一个竞赛平台,还鼓励参赛者通过讨论和分享解题思路来学习和提高。在比赛结束后,ATCoder将提供详细的解题分析和解题报告,帮助参赛者了解每个题目的最佳解决方法,并提供参考答案和示例代码。 通过参加ATCoder Beginner Contest 235,参赛者可以提升他们的编程技能,锻炼逻辑思维能力,并与全球的编程爱好者交流。无论是初学者还是有经验的编程者,ABC 235都是一个很好的学习和挑战的机会。 ### 回答3: AtCoder Beginner Contest 235 是一个在 AtCoder 上的初级比赛。该比赛通常会吸引很多新手程序员参加。它由 AtCoder 组织主办,旨在帮助新手提高编程技能以及在竞赛中锻炼自己。 比赛的题目难度由易到难,共有四个问题。通常,第一个问题是一个简单的数学问题,要求解决一个简单的算术运算。第二个问题可能是一个字符串操作问题,需要对给定的字符串进行处理。第三个问题可能是一个动态规划或贪心算法问题,需要细心分析问题,找出最优解。最后一个问题通常是一个较难的图论或组合问题,需要一些高级算法来解决。 参赛选手在比赛开始后有一定的时间限制来解决这些问题。他们可以使用自己熟悉的编程语言来实现解决方案。然后他们将自己的程序提交到 AtCoder 的在线评测系统中进行评测。评测结果会即时显示,并将参赛选手的成绩排名和讨论解答过程的视频分享给其他选手。 参加 AtCoder Beginner Contest 235 对于新手来说是一个很好的机会。通过解决这些问题,他们可以练习编程技巧,提高解决问题的能力。比赛结束后,他们还可以看到其他选手的解答,学习他们的思路和方法。同时,比赛的排名和奖励也是一种鼓励和激励新手继续努力学习的方式。 总之,AtCoder Beginner Contest 235 是一个对于新手非常友好的比赛,它提供了一个锻炼和展示编程技能的平台。无论是对于新手还是更有经验的选手,参加这样的比赛都是一个宝贵的机会。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值