Codeforces 552C Vanya and Scales(思路)
题目大概说有101个质量w0、w1、w2、...、w100的砝码,和一个质量m的物品,问能否在天平两边放物品和砝码使其平衡。
哎,怎么没想到。。注意到w0、w1、w2、...、w100——
把m转化成w进制数,枚举每一位:
- 如果第i位是0那OK;
- 如果是1那就要把砝码wi放在天平另一边抵消;
- 如果是w-1那就要把砝码wi放到天平同一边,使其变为0并进位,这时第i+1位的权+1;
- 而如果是其他情况,那么肯定不能平衡了。
#include<cstdio>
#include<cstring>
using namespace std;
int wi[];
int main(){
int w,m;
scanf("%d%d",&w,&m);
for(int i=; m; ++i){
wi[i]=m%w;
m/=w;
}
bool flag=;
for(int i=; i<=; ++i){
if(wi[i]>=w){
int t=wi[i];
wi[i]=w%t;
wi[i+]+=w/t;
}
if(wi[i]!= && wi[i]!= && wi[i]!=w-){
flag=;
break;
}
if(wi[i]==w-){
++wi[i+];
}
}
if(flag) puts("YES");
else puts("NO");
return ;
}
Codeforces 552C 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 C. Vanya and Scales
C. Vanya and Scales Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w10 ...
- 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 677D Vanya and Treasure 暴力+BFS
链接 Codeforces 677D Vanya and Treasure 题意 n*m中有p个type,经过了任意一个 type=i 的各自才能打开 type=i+1 的钥匙,最初有type=1的钥 ...
- codeforces 492E. Vanya and Field(exgcd求逆元)
题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...
随机推荐
- 三、jQuery--Ajax基础--Ajax全接触--Ajax在JS中的应用
Ajax的全称:Asynchronous JavaScript And XML(异步的 JavaScript 和 XML). Ajax不是某种编程语言,是一种在无需重新加载整个网页的情况下能够更新部分 ...
- Android Tab -- 使用Fragment、FragmentManager来实现
原文地址:http://blog.csdn.net/crazy1235/article/details/42678877 效果: 代码:https://github.com/ldb-github/La ...
- 与你相遇好幸运,Tippecanoe在Centos下の安装
全新的CentOS 7 x86_64 安装编译工具 yum install -y gcc automake autoconf libtool make yum insyall -y gcc gcc-c ...
- Python 与 C# lambda表达式比较
Python里到lambda表达式非常简约, lam =lambda a: a*2 --> lam(3) 6 在某些情况下确实挺好用到.但是相比C#到lambda表达式,还是不够强大(我不是在黑 ...
- [LeetCode] Isomorphic Strings
Isomorphic Strings Total Accepted: 30898 Total Submissions: 120944 Difficulty: Easy Given two string ...
- Analysis Services OLAP 概述2
在DW/BI系统中,关系型数据库是存储和管理数据的最佳场所.但是关系数据库本身的智能化程度不够.关系型数据库缺乏如下功能: 丰富的元数据,帮助用户浏览数据和创建查询. 强大的分析计算和函数,在对上下文 ...
- Getting Started with Blocks
本文来源为:developer.apple.com,仅仅是博主练习排版所用. Getting Started with Blocks The following sections help you t ...
- [Eclipse] Eclipse is running in a JRE, but a JDK is required
安装Maven后每次启动出现警告信息: Eclipse is running in a JRE, but a JDK is required Some Maven plugins may not wo ...
- ARM寻址方式,王明学learn
ARM寻址方式 所谓寻址方式就是处理器根据指令中给出的信息来找到指令所需操作数的方式. 一.立即数寻址 立即数寻址,是一种特殊的寻址方式,操作数本身就在指令中给出,只要取出指令也就取到了操作数.这个操 ...
- LeetCode——Rotate Image(二维数组顺时针旋转90度)
问题: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockw ...