CodeForces 552C Vanya and Scales(进制转化)
2016-02-02 22:33
337 查看
题意:
代码:
[code]转化成w进制表示就行了,如果有某一位是1表示放在异侧,是w-1就放在同侧。
代码:
[code]// // Created by CQU_CST_WuErli // Copyright (c) 2015 CQU_CST_WuErli. All rights reserved. // // #include<bits/stdc++.h> #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <string> #include <vector> #include <list> #include <map> #include <queue> #include <stack> #include <set> #include <algorithm> #include <sstream> #define CLR(x) memset(x,0,sizeof(x)) #define OFF(x) memset(x,-1,sizeof(x)) #define MEM(x,a) memset((x),(a),sizeof(x)) #define For_UVa if (kase!=1) cout << endl #define BUG cout << "I am here" << endl #define lookln(x) cout << #x << "=" << x << endl #define SI(a) scanf("%d",&a) #define SII(a,b) scanf("%d%d",&a,&b) #define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c) #define rep(flag,start,end) for(int flag=start;flag<=end;flag++) #define Rep(flag,start,end) for(int flag=start;flag>=end;flag--) #define Lson l,mid,rt<<1 #define Rson mid+1,r,rt<<1|1 #define Root 1,n,1 #define BigInteger bign template <typename T> T gcd(const T& a,const T& b) {return b==0?a:gcd(b,a%b);} const int MAX_L=2005;// For BigInteger const int INF_INT=0x3f3f3f3f; const long long INF_LL=0x7fffffff; const int MOD=1e9+7; const double eps=1e-9; const double pi=acos(-1); typedef long long ll; using namespace std; ll w,m; int p[100]; int main(){ #ifdef LOCAL freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin); // freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout); #endif while (cin >> w >> m) { int cnt=0; while (m) { p[cnt++]=m%w; m/=w; } int ok=1; rep(i,0,cnt-1) { if (p[i]>=w) { p[i]-=w; p[i+1]++; } if (p[i]==w-1) { p[i]=0; p[i+1]++; } else if (p[i]>1 && p[i]<w-1) ok=0; } puts(ok?"YES":"NO"); } return 0; }
相关文章推荐
- Java中byte与16进制字符串的互换原理
- 第十一天
- CodeForces 621A Wet Shark and Odd and Even
- 事务复制-大批量DEL操作
- 记录遇到的Python陷阱和注意点
- 记一次面试经验
- android实现微信自动抢红包
- Hadoop 之 文件切分算法
- 《笨办法学Python》 第31课手记
- 【转】 Android的NDK开发(1)————Android JNI简介与调用流程
- 嵌入式Linux之旅——环境搭建篇之烧写裸机程序
- c++转换构造函数和类型转换函数
- CDOJ 1273 God Qing's circuital law
- Block使有注意点
- 面试笔试杂项积累-leetcode 76-80
- 如何使用Java语言实现一个网页爬虫
- java 父类引用指向子类对象
- Error installing mysql2: ERROR: Failed to build gem native extension
- GLEW-1.13.0在win7(64位)+VS2010下的配置方法
- 23种设计模式(3):抽象工厂模式