CodeForces 552C Vanya and Scales
来源:互联网 发布:淘宝如何减少竞店流失 编辑:程序博客网 时间:2024/06/05 02:46
FAQ | About Virtual Judge | Forum | Discuss | Open Source Projec
//题意:输入w,m。
表示给你一个w,你可以使用w^0,w^1,w^2w^3.........w^100;这一百零一个数,现在又给你一个数m,让你将m放到天平的右边,现在问你能否通过在两边天平上添加那101个砝码使得天平平衡。
求M=W(a)+W(b)+...+W(c)-W(d)-W(e)-....-W(f)其中W(a)为w的a次方且括号内的数不相同。
解题思路:将等式两边同时除以W若M%W!=0既考虑存在W(0)即考虑(M+1)%W和(M-1)%W若均不存在则无解否侧循环除以W当最终W为0时即有解否则无解
代码:
#include<iostream>#include<cstdio>#include<cmath>#include<queue>#include<algorithm>#include<cstring>#define max(a,b)(a>b?a:b)#define min(a,b)(a<b?a:b)#define INF 999999999using namespace std;typedef long long ll;int main(){ ll w,m; while(scanf("%lld%lld",&w,&m)!=EOF) { while((m+1)%w==0 || (m-1)%w==0 || m%w==0) { if((m-1)%w==0) m=(m-1)/w; else if((m+1)%w==0) m=(m+1)/w; else if(m%w==0) m=m/w; if(m==0) break; } if(m==0) printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- Codeforces 552C Vanya and Scales
- codeforces 552 C Vanya and Scales
- [CodeForces 552C]Vanya and Scales[math]
- CodeForces 552C:Vanya and Scales【技巧】
- CodeForces 552C-Vanya and Scales【思维】
- Codeforces 552C. Vanya and Scales【巧】
- CodeForces 552C Vanya and Scales
- codeforces 552C Vanya and Scales 【思维】
- 【30.23%】【codeforces 552C】Vanya and Scales
- codeforces 552C Vanya and Scales(进制转化)
- CodeForces 552C. Vanya and Scales(进制+思维)
- Codeforces #308 C. Vanya and Scales
- Codeforces 552.C Vanya and Scales
- Codeforces #369C Vanya and Scales
- CF 552-C. Vanya and Scales
- CF 552 C. Vanya and Scales
- codeforces #308C C. Vanya and Scales(数制转换)
- C. Vanya and Scales(Codeforces Round #308 (Div. 2))
- Android Service中如何启动Activity(发生异常的原因,如何解决)
- 文章标题
- 【NOIP提高组2015D2T1】uva 714 copying books【二分答案】——yhx
- 【NOIP合并果子】uva 10954 add all【贪心】——yhx
- 基于Docker的分布式服务研发实践
- CodeForces 552C Vanya and Scales
- CSS学习之<img> & Background - CSS: The Missing Manual
- 软件版本英文缩写小常识
- webservice客户端如何获取服务端返回的自定义类
- 从2月14号开始,上传AppStore会碰到:Failed to locate or generate matching
- EditText 输入时动态显示结果
- Swing【java】
- IRQL APC_LEVEL and APC
- Mongodb 操作