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 人,每人有两中选择,因此本题最多的可能性就是 种,因此我们完全可以在 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;
}