Codeforces Round #328 (Div. 2) 592ABC题解
来源:互联网 发布:arduino蓝牙发送数据 编辑:程序博客网 时间:2024/06/06 02:48
题目链接:
A: 给出8*8的一个棋盘, W为A的棋子, B为B的棋子. 每个棋子只能向上或者向下走, 且不能覆盖或者跳跃棋子, 问你最终谁获胜.
模拟题, 遍历每一列, 记录最考上的W以及最靠下的B的位置.
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;const int MAXN = 10;char map[MAXN][MAXN];int a = MAXN, b = MAXN;int main(int argc, char const *argv[]){ for(int i = 0; i < 8; ++i) scanf("%s", map[i]); for(int j = 0; j < 8; ++j) { bool flag = false; for(int i = 0; i < 8; ++i) { if(map[i][j] == 'W' && !flag) a = min(a, i); if(map[i][j] == 'B') flag = true; } flag = false; for(int i = 7; i >= 0; --i) { if(map[i][j] == 'B' && !flag) b = min(b, 7 - i); if(map[i][j] == 'W') flag = true; } } if(a <= b) printf("A\n"); else printf("B\n"); return 0;}
规律题, 自己画几组后就发现答案为(n - 2) ^ 2.
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;typedef long long ll;int main(int argc, char const *argv[]){ ll n; scanf("%lld", &n); n -= 2; printf("%lld\n", n * n); return 0;}
C: 有一个跑道, 终点为1 ~ t - 1, 两个人的步速分别为w, b, 问你选择平等的概率是多少.
数学题, 注意到数据的范围, 将要比较的数据转化为double型运用log()函数就可以解决. 通过gcd, lcm即可解决.
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"#include "cmath"using namespace std;typedef long long ll;ll t, w, b;ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a % b);}ll lcm(ll a, ll b){ return a / gcd(a, b) * b;}bool judge(ll a, ll b, ll c){ if(log(1.0 * a) + log(1.0 * b) - log(1.0 * gcd(a, b)) > log(1.0 * c)) return true; return false;}int main(int argc, char const *argv[]){ scanf("%lld%lld%lld", &t, &w, &b); if(w == b) { printf("1/1\n"); return 0; } ll x, y = t; if(judge(w, b, t)) x = min(w - 1, min(b - 1, t)); else { ll l = lcm(w, b), g = t / l; if(l * g + min(w, b) <= t) x = (g + 1) * min(w, b) - 1; else x = g * (min(w, b) - l) + t; } printf("%lld/%lld\n", x / gcd(x, y), y / gcd(x, y)); return 0;}
1 0
- Codeforces Round #328 (Div. 2) 592ABC题解
- [Codeforces Round #309 (Div. 2)] #ABC题解
- [Codeforces Round #310 (Div. 2)] #ABC题解
- Codeforces Round #312 (Div. 2) ABC题解
- Codeforces Round #331 (Div. 2) (ABC题解)
- Codeforces Round #418 (Div. 2) 题解 ABC
- Codeforces Round #259 (Div. 2) ABC简要题解
- Codeforces Round #323 (Div. 2) ABC题解(全是暴力)
- Codeforces Round #325 (Div. 2) 586ABC题解
- Codeforces Round #326 (Div. 2) 588ABC题解
- Codeforces Round #327 (Div. 2) 591ABC题解
- Codeforces Round #331 (Div. 2) 596ABC题解
- Codeforces Round #428 (Div. 2) 题解(ABC)
- Codeforces Round #199 (Div. 2) (ABC)
- Codeforces Round #226 (Div. 2) ABC
- Codeforces Round #247 (Div. 2) ABC
- Codeforces Round #249 (Div. 2) ABC
- Codeforces Round #249 (Div. 2) ABC
- 静态局部变量初始化次数的控制
- Eigen与Matlab函数对应
- 异常处理:User_$$_javassist_1 cannot be cast to javassist.util.proxy.Proxy
- 机器学习的类型和一些概念
- C#调用Excel的宏
- Codeforces Round #328 (Div. 2) 592ABC题解
- Burpsuit使用——暴力破解(Intruder入侵)
- ARToolKit安装指南—第一个程序
- 在html中使用视频
- Android中三大组件和Fragment生命周期汇总
- html中实现对图片的简单拖放
- Java --- Bluetooth Device & Service Discovery Code examples
- Colt matrix library example code
- HideFlags