AtCoder Beginner Contest 190 简易题解报告和 AC 代码(缺 D、E、F 题)

A - Very Very Primitive Game

题目链接

https://atcoder.jp/contests/abc190/tasks/abc190_a

简易题解

还是一个签到题。

我们根据输入 c 进行判断。如果 c==0,表示 Takahashi 先开始,那么 Takahashi 必须必 Aoki 有跟多的糖果才能赢,即 a>b。同理,如果 c==1,表示 Aoki 先开始,那么 Aoki 必须必 Takahashi 有跟多的糖果才能赢,即 b>a。

AC 代码

#include <bits/stdc++.h>
 
using namespace std;
 
//如果提交到OJ,不要定义 __LOCAL
//#define __LOCAL
 
int main() {
#ifndef __LOCAL
    //这部分代码需要提交到OJ,本地调试不使用
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    int a,b,c;
    cin>>a>>b>>c;
    if (0==c) {
        if (a>b) {
            cout<<"Takahashi\n";
        } else {
            cout<<"Aoki\n";
        }
    } else {
        if (b>a) {
            cout<<"Aoki\n";
        } else {
            cout<<"Takahashi\n";
        }
    }
#ifdef __LOCAL
    //这部分代码不需要提交到OJ,本地调试使用
    system("pause");
#endif
    return 0;
}

B - Magic 3

题目链接

https://atcoder.jp/contests/abc190/tasks/abc190_b

简易题解

模拟题。

题目的核心是:However, the monster is strong enough to avoid taking damage from spells taking S or more seconds to cast and spells with powers D or less。也就是说,如果魔法师的施法时间超过 S 或者伤害小于 D 都无法伤害怪物。因此,我们只需要模拟整个过程,判断能否对怪物产生伤害即可。

AC 代码

//https://atcoder.jp/contests/abc190/tasks/abc190_b
//B - Magic 3  
#include <bits/stdc++.h>
 
using namespace std;
 
//如果提交到OJ,不要定义 __LOCAL
//#define __LOCAL
typedef long long ll;
 
int main() {
#ifndef __LOCAL
    //这部分代码需要提交到OJ,本地调试不使用
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    int n,s,d;
    cin>>n>>s>>d;
 
    for (int i=1; i<=n; i++) {
        int x,y;
        cin>>x>>y;
        if (x<s && y>d) {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
 
#ifdef __LOCAL
    //这部分代码不需要提交到OJ,本地调试使用
    system("pause");
#endif
    return 0;
}

C - Bowls and Dishes

题目链接

https://atcoder.jp/contests/abc190/tasks/abc190_c

简易题解

考点数据结构 + DFS。

根据数据范围,1 ≤ K ≤ 16,也就是说最多只有 16 人,每人有两中选择,因此本题最多的可能性就是 2^{16}=65536 种,因此我们完全可以在 1 秒内完成枚举。这样,问题就变为如何使用合适的数据结构来描述题目。我们也可以将每次的选择看做一个 STL 的 pair,使用 vector 来保存。数据保存好后,我们可以使用 DFS 思路来解题。

AC 代码

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int MAXM=1e2+4;
bool flag[MAXM];//保存标志
vector<ii> conds;//保存条件
vector<ii> opt;//用户选择
int n,m;
int k;
int ans;

void dfs(int t) {
    //出口
    if (k==t) {
        int now=0;
        for (ii cond:conds) {
            if (false==flag[cond.first] && false==flag[cond.second]) {
                now++;
            }
        }
        ans = max(ans, now);
        return;
    }
    
    //递归
    ii now = opt[t];
    if (flag[now.first]) {
        flag[now.first] = false;
        dfs(t+1);
        flag[now.first] = true;
    }
    if (flag[now.second]) {
        flag[now.second] = false;
        dfs(t+1);
        flag[now.second] = true;
    }
    if (false==flag[now.first] && false==flag[now.second]) {
        dfs(t+1);
    }
}

int main() {
    cin>>n>>m;
    for (int i=1; i<=m; i++) {
        int a,b;
        cin>>a>>b;
        flag[a]=true;
        flag[b]=true;
        conds.push_back({a, b});
    }
    cin>>k;
    for (int i=1; i<=k; i++) {
        int a,b;
        cin>>a>>b;
        opt.push_back({a, b});
    }

    dfs(0);
    cout<<ans<<"\n";

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

努力的老周

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

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

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

打赏作者

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

抵扣说明:

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

余额充值