CodeForces #426 div2 C The Meaningless Game
来源:互联网 发布:淘宝天猫入驻条件 编辑:程序博客网 时间:2024/06/07 18:55
其实很简单,如果正确的话,那么两个数相乘应该是每个书的三次幂。
从这个进行入手,开立方根,然后检验是否成立。
比赛的时候WA 2 因为要保证a和b都要能够整除这个数
然后就WA 3了。。。
悲伤辣么大。。。枉费我先开C题的心机TAT
WA 3是因为我一开始打的表没有考虑 1 1这个特殊情况,输出应为Yes
这道题还有一洗比较简单的方法实现,主要就是浮点数四舍五入这么一个地方需要注意:
#include <bits/stdc++.h>using namespace std;const int maxn=1e6+5;typedef long long ll;const ll inf=1e9+5;int main(int argc, char const *argv[]){int n;ll a,b;while(~scanf("%d",&n)){for(int i=0;i<n;i++){scanf("%lld %lld",&a,&b);ll temp=(ll)(pow(a*b*1.0,1.0/3)+0.5);if((temp*temp*temp==a*b)&&(a%temp==0)&&(b%temp==0)){printf("Yes\n");}else{printf("No\n");}}}return 0;}
另外的一种实现方法,我们可以看到,这个a和b的乘积开立方根并不大,大概1e6左右,那么我们可以先打个表。
#include <bits/stdc++.h>using namespace std;const int maxn=1e6+5;typedef long long ll;const ll inf=1e9+5;map<ll,ll> mapll;void init(){for(ll i=1;i<maxn;i++){ll temp=i*i*i;mapll[temp]=i;}}int main(int argc, char const *argv[]){int n;init();while(~scanf("%d",&n)){ll a,b;for(int i=0;i<n;i++){scanf("%lld %lld",&a,&b);ll temp=a*b;if(mapll[temp]){ll cnt=mapll[temp];if(a%cnt==0&&b%cnt==0){printf("Yes\n");}else{printf("No\n");}}else{printf("No\n");}}}return 0;}
阅读全文
0 0
- 【CodeForces】426Div2 C The Meaningless Game
- CodeForces #426 div2 C The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game C. The Meaningless Game
- Codeforces Round #426 (Div. 2) C:The Meaningless Game The Meaningless Game
- (Codeforces Round #426 (Div. 2)) C.The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
- Codeforces 834(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 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】834C. The Meaningless Game
- codeforces 834C (The Meaningless Game)
- Codeforces 834C The Meaningless Game【思维】
- codeforces 834 C The Meaningless Game
- codeforces 834 C The Meaningless Game
- Linux查看系统信息的一些命令及查看已安装软件包的命令
- JavaScript学习思维导图----总结
- proxychains
- 每天五分钟linux(13)-less
- Django提交表单出错”django, CSRF token missing or incorrect”
- CodeForces #426 div2 C The Meaningless Game
- AtomicInteger源码分析
- sqoop运用
- Tomcat中垃圾回收调优
- 一个简单的问题:==与equals的区别
- C语言(9)C小加 之 随机数
- 名企笔试:支付宝红包口令(2015 阿里笔试)
- 【总结】DFS算法模板及题型分类
- Python中对元组和列表按条件进行排序的方法示例