codeforces C. Vanya and Scales
Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some integer not less than 2(exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.
The first line contains two integers w, m (2 ≤ w ≤ 109, 1 ≤ m ≤ 109) — the number defining the masses of the weights and the mass of the item.
Print word 'YES' if the item can be weighted and 'NO' if it cannot.
3 7
YES
100 99
YES
100 50
NO
Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1.
Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100.
Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
题意:给定两个数,m和w,现有w^0, w^1, w^2...w^100各一个重量的mass, 用其中的一些mass,时候能称出m的重量。
也就是有如下图的式子:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std; int main(){
int m, w;
cin>>w>>m;
while(m){
if(!((m-)%w)) m--;
else if(!((m+)%w)) m++;
else if(m%w){
cout<<"NO"<<endl;
return ;
}
m/=w;
}
cout<<"YES"<<endl;
return ;
}
codeforces C. Vanya and Scales的更多相关文章
- CodeForces 552C Vanya and Scales
Vanya and Scales Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Codeforces 552C Vanya and Scales(进制转换+思维)
题目链接:http://codeforces.com/problemset/problem/552/C 题目大意:有101个砝码重量为w^0,w^1,....,w^100和一个重量为m的物体,问能否在 ...
- Codeforces 552C Vanya and Scales(思路)
题目大概说有101个质量w0.w1.w2.....w100的砝码,和一个质量m的物品,问能否在天平两边放物品和砝码使其平衡. 哎,怎么没想到..注意到w0.w1.w2.....w100—— 把m转化成 ...
- Codeforces Round #308 (Div. 2) C. Vanya and Scales dfs
C. Vanya and Scales Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/p ...
- 暴力/进制转换 Codeforces Round #308 (Div. 2) C. Vanya and Scales
题目传送门 /* 题意:问是否能用质量为w^0,w^1,...,w^100的砝码各1个称出重量m,砝码放左边或在右边 暴力/进制转换:假设可以称出,用w进制表示,每一位是0,1,w-1.w-1表示砝码 ...
- Codeforces Round #308 (Div. 2)----C. Vanya and Scales
C. Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Vanya and Scales(思维)
Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- codeforces 492E. Vanya and Field(exgcd求逆元)
题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...
- Codeforces 677D Vanya and Treasure 暴力+BFS
链接 Codeforces 677D Vanya and Treasure 题意 n*m中有p个type,经过了任意一个 type=i 的各自才能打开 type=i+1 的钥匙,最初有type=1的钥 ...
随机推荐
- (转)对博士学位说永别 by 王珢
对博士学位说永别 by 王垠 经过深思熟虑之后,我决定再次“抛弃”我的博士学位.这是我第三次决定离开博士学位,也应该是最后一次了.这应该不是什么惊人的消息,因为我虽然读博士10年了,可是我的目标从来就 ...
- C语言dll文件的说明以及生成、使用方法
最近在搞一些小项目,由于要涉及到跟其它语言进行交互,动态链接库变成了不二的选择.为此也查阅了很多资料,将动态链接库的相关知识在此做一个整理. 一.动态链接库概述 动态链接库(Dynamic Link ...
- nodejs学习之events
在node里许多对象都发出事件:一个net.Server对象每次一个连接到来,都发出一个事件,一个fs.readStream对象在文件打开时放出一个事件.所有能放出事件的对象都是event.Event ...
- ViewPager自动轮播
Android使用ViewPager实现左右循环滑动及轮播效果 ViewPager是一个常用的android组件,不过通常我们使用ViewPager的时候不能实现左右无限循环滑动,在滑到边界的时候 ...
- 计数排序和桶排序(Java实现)
目录 比较和非比较的区别 计数排序 计数排序适用数据范围 过程分析 桶排序 网络流传桶排序算法勘误 桶排序适用数据范围 过程分析 比较和非比较的区别 常见的快速排序.归并排序.堆排序.冒泡排序等属于比 ...
- C语言的傻瓜式随笔(二):全局变量、预编译、goto
函数的作用:可以实现代码的重用. 函数只需要定义1次,那么函数中的代码就可以随意的调用. -某不知出处的基本概念 学而时习之,如有误笔,请指正 一.goto跳转语句 goto在C语言的作用 ...
- GPRS 接入外网的过程
请问GPRS模块与Internet上主机的连接.数据传输过程 虽然按照GPRS模块的说明文档能够通过内嵌TCP/IP实现数据的传输,但是对GPRS模块和主机之间的连接关系了解得不是很多.有谁可以介绍一 ...
- C++ 控制台代码输出控制
在C++控制台应用程序中可以控制控制台输出的字体颜色和 接受任意按键退出 #ifndef CONSOLE_UTILS_H #define CONSOLE_UTILS_H #include <wi ...
- 使用JDBC调用存储过程
DELIMITER $$ DROP PROCEDURE IF EXISTS `jdbc`.`addUser` $$ ),in birthday date,in money float,out pid ...
- 使用 Productivity Power Tools 2013来帮助你提高 VS2013的工作效率
Visual Studio Gallery中发布了Productivity Power Tools 2013 的更新.在此版本中,此版本解决了客户报告的大量错误和问题,并介绍了一项称为语法行压缩的新功 ...