AtCoder题解——Beginner Contest 179——B - Go to Jail

本文解析了AtCoderBeginnerContest179B题,介绍了一种简单的方法来判断是否存在连续三行双骰子投掷结果相同的情况,并提供了AC参考代码。

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

题目相关

题目链接

AtCoder Beginner Contest 179 B 题,https://atcoder.jp/contests/abc179/tasks/abc179_b

Problem Statement

Tak performed the following action NN times: rolling two dice. The result of the ii-th roll is D_{i,1} and D_{i,2}.

Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one ii such that D{i,1}=D{i,2}D{i+1,1}=D{i+1,2} and D{i+2,1}=D{i+2,2} hold.

Input

Input is given from Standard Input in the following format:

N
D1,1 D1,2
⋮
DN,1 DN,2

Output

Print Yes if doublets occurred at least three times in a row. Print No otherwise.

Samples1

Sample Input 1

5
1 2
6 6
4 4
3 3
3 2

Sample Output 1

Yes

Explaination

From the second roll to the fourth roll, three doublets occurred in a row.

Samples2

Sample Input 2

5
1 1
2 2
3 4
5 5
6 6

Sample Output 2

No

Samples3

Sample Input 3

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

Sample Output 3

Yes

Constraints

  • 3 ≤ N≤100
  • 1 ≤ Di,j ≤ 6
  • All values in input are integers.

题解报告

题目翻译

给 N 个行,每行 2 个数,这样构成一个 N*2 的矩阵,问矩阵中是否存在连续三行,满足 Di1=Di2。

题目分析

非常简单的开胃题,直接遍历数组即可得到答案。

样例数据分析

样例 1

第 2、3、4 行的 Di,1 = Di,2,因此输出 Yes。

样例 2

没有连续的三行满足条件,因此输出 Yes。

样例 3

第 1、2、3 行的 Di,1 = Di,2,因此输出 Yes。

AC 参考代码

//https://atcoder.jp/contests/abc179/tasks/abc179_b
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAXN=1e2+4;
int sz[MAXN][2+2];
 
int main() {
    int n;
    cin>>n;
    for (int i=1; i<=n; i++) {
        cin>>sz[i][1]>>sz[i][2];
    }

    for (int i=1; i<=n-2; i++) {
        if (sz[i][1]==sz[i][2] && sz[i+1][1]==sz[i+1][2] && sz[i+2][1]==sz[i+2][2]) {
            cout<<"Yes\n";
            return 0;
            }         
    }
    cout<<"No\n";
 
    return 0;
}

时间复杂度

O(N)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力的老周

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值