Codeforces Round #426 (Div. 2) C. The Meaningless Game & A, B题代码及错误总结
来源:互联网 发布:js的某个div全屏显示 编辑:程序博客网 时间:2024/06/04 20:03
题目链接: The Meaningless Game
题目大意
两个人玩游戏, 每次选一个自然数k(k>=1), 然后两个人中的随机一个人分数乘以k^2, 另一个人分数乘以k, 初始时两个人分数都是为1, 若干轮后两个人的分数分别是a, b;
现在告诉你两个人最后的分数a, b, 求可不可能出现这种局面
思路
根据游戏规则, a和b一定要能够分解成类似下面这种形式:
令
令
并且有
如何求出t呢? 首先想到的是最大公因数,
但是当
但是可以
这种情况我们可以从t取出一个x(
所以只要判断t/(ab)是能够被开三次方, 即存在
注意int溢出, 还有测试组数比较多, 注意用cin可能会TLE
错误总结
A题减法后取模忘了+4, WA
B题两层循环变量都是i结果WA(居然过了样例), 内层循环改成j后结果内部语句有一个i忘记改成j了, 又WA了一发
C题用cin结果TLE了, 没怎么考虑改成scanf就交了, 结果WA了, 最后仔细考虑了才AC的
5发WA除了C题一发是思路没有理清, 其他的全都是粗心, 完全可以避免的, 今天晚上简直ZZ了, 心疼250pt, 作为一个完全靠水题的弱, 这是绝对要避免的
C题代码
#include <bits/stdc++.h>using namespace std;int gcd(int a, int b){ return b ? gcd(b, a%b) : a; }int main(){ set<int> s; int a, b, n, t; for(int i=1; i<=1001; ++i) s.insert(i*i*i); for(scanf("%d", &n); n; --n) { scanf("%d%d", &a, &b); t = gcd(a, b); a/=t, b/=t; long long x = t/(1ll*a*b); if(s.count(x) && x*a*b==t) puts("Yes");//x能开三次方(结果是整数) && t能被a*b整除 else puts("No"); } return 0;}
A题
WA原因: 减法取模忘记加上mod
#include <bits/stdc++.h>using namespace std;int main(){ char c1, c2; int n; cin >> c1 >> c2 >> n; n %= 4; map<char, int> mp; mp['^'] = 0; mp['>'] = 1; mp['v'] = 2; mp['<'] = 3; int x = mp[c1], y = mp[c2]; if((x+n) % 4 == y && (x-n+4)%4 != y) cout << "cw" << endl; else if((x+n) % 4 != y && (x-n+4)%4 == y) cout << "ccw" << endl; else cout << "undefined" << endl; return 0;}
B题
WA原因: 两层循环变量命名混乱
#include <bits/stdc++.h>using namespace std;const int maxn = 1e6 + 100;int l[30], r[30];char s[maxn];int n, k;int main(){ cin >> n >> k >> s; fill(l, l+30, 1e9); fill(r, r+30, -1); int len = strlen(s); for(int i=0; i<len; ++i) { int x = s[i]-'A'; l[x] = min(l[x], i); r[x] = max(r[x], i); } for(int i=0; i<len; ++i) { int cnt = 0; for(int j=0; j<26; ++j) { if(l[j]<=i && i<=r[j]) ++cnt; } if(cnt > k) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0;}
- Codeforces Round #426 (Div. 2) C. The Meaningless Game & A, B题代码及错误总结
- Codeforces Round #426 (Div. 2) A B C The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game C. The Meaningless Game
- Codeforces Round #426 (Div. 2) B.The Festive Evening+C.The Meaningless Game
- (Codeforces Round #426 (Div. 2)) C.The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
- Codeforces Round #426 (Div. 2)-C. The Meaningless Game
- Codeforces Round #426 (Div. 2) C The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
- Codeforces Round #426 (Div. 2) C The Meaningless Game
- Codeforces Round #426 (Div. 2) C:The Meaningless Game The Meaningless Game
- Codeforces Round #426 (Div. 1) A. The Meaningless Game
- Codeforces Round #426 (Div. 2)The Meaningless Game(思维+二分)
- Codeforces Round #426 (Div. 2)The Meaningless Game(思维+二分)
- Codeforces Round #426 (Div. 2)The Meaningless Game【数学题】【水题】
- Codeforces Round #426 (Div. 2)The Meaningless Game(思维+二分)
- Codeforces Round #426 (Div. 2) C. The Meaningless Game 思维 D. The Bakery dp
- ITIL 2011 服务管理与认证读书笔记——第四章 服务设计
- 深究js(九)——语句的其他类型(语句Ⅳ)
- Angular 2 路由
- 深究js(十)——语句和表达式的区别(语句Ⅴ)
- bzoj 2820: YY的GCD(莫比乌斯反演)
- Codeforces Round #426 (Div. 2) C. The Meaningless Game & A, B题代码及错误总结
- java数据结构排序之冒泡排序
- linux下如何根据端口号查看对应进程的ID
- JavaScript设计模式(三) 数据访问对象模式
- 一分钟了解“结构张量”
- IOS下的 NSTimer与Run loop Modes
- 二叉树问题---较为直观的打印二叉树
- java8 lambda表达式在集合中的应用
- 二叉树问题---打印二叉树的边界节点