【codeforces 758D】Ability To Convert
【题目链接】:http://codeforces.com/contest/758/problem/D
【题意】
给你一个n进制的数k;
问你它可能的最小的十进制数是多少;
【题解】
从右往左;
获取数字;
如果这个数字小于n就一直往左扩大;
尽量大;
这样把尽可能多的数字放在权值的低位;
这样n进制数的位就会尽可能地少;
十进制数也就尽可能地小了;
但是有前导0的情况;
这个判断前导0有点麻烦;
即
10011
你不好获取
0011这个数字的信息;
即是不是到了从右往左数第二个0的时候,就该停下来了;
这个可以先预处理出101..12
然后看看当前处理的数字的可能最小值是不是小于n;如果最小的都大于等于n了就不用继续了;
必须得这样做不然对于
2
10000000000000000000000000
这样的数据;
如果你算到了第一个数字才发觉大于n了;
那么你算出来的数字 10000000000000000000000000可能会爆long long
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
int n;
char s[100];
LL temp = 1,ans = 0,tenpow[15];
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
rei(n);
cin >> (s+1);
int len = strlen(s+1),pre = len;
LL dd = 0,now = 1;
tenpow[0] = 1;
rep1(i,1,12)
tenpow[i] = tenpow[i-1]*10;
rep2(i,len,1)
{
LL tdd = dd+now*(s[i]-'0');
LL ju = (pre-i+1);
now=now*10;
if ((s[i]!='0' ||(s[i]=='0' && tenpow[ju]<n)||i==len )&& tdd<n)
{
dd = tdd;
}
else
//tdd>=n
{
int j = i+1;
while (s[j]=='0' && j+1<=pre)
{
j++;
}
ans += dd*temp;
temp=temp*n;
i = j-1;
pre = i;
dd = s[i]-'0';
now = 10;
}
}
ans += dd*temp;
cout << ans << endl;
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 758D】Ability To Convert的更多相关文章
- Codeforces 758D:Ability To Convert(思维+模拟)
http://codeforces.com/problemset/problem/758/D 题意:给出一个进制数n,还有一个数k表示在n进制下的值,求将这个数转为十进制最小可以是多少. 思路:模拟着 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
随机推荐
- Consider using EXISTS instead of IN
redgate给出的提示 https://documentation.red-gate.com/codeanalysis/performance-rules/pe019 In theory, EXIS ...
- lightbox2
http://lokeshdhakar.com/projects/lightbox2/ 简单的demo <html> <head id="head"> &l ...
- VS2010 使用TeeChart绘图控件 - 之二 - 绘制图形(折线图,柱状图)
1.前期准备 具体可见VS2010 使用TeeChart绘图控件 - 之一 控件和类的导入 1. 1 添加TeeChart控件,给控件添加变量m_TeeChart 添加TeeChart控件,右击控件, ...
- Finding Nemo(搜索)
http://poj.org/problem?id=2049 题意:有一个迷宫,迷宫中有墙.门和空地.有M道墙,每一道墙用(x,y,d,t)表示,(x,y)表示墙的起始坐标,(d=1,t)表示向上t个 ...
- es6 import 与 export
1.export 命令 export 命令用于规定模块的对外接口. 一个模块就是一个独立的文件.该文件内部所有的变量,外部无法获取.要想外部能够读取模块内部的某个变量,就必须使用 export 关键字 ...
- 巴什博弈----hdu2147-----较难
kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Java/Others)Total ...
- ACM_出题人这样不好吧
出题人这样不好吧 Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为编协的第一次月赛,肯定是要有防AK(ALL KILL)的题目 ...
- reactnative(2) - Navigator 使用案例
'use strict'; import React, { Component } from 'react'; import { AppRegistry, ScrollView, StyleSheet ...
- (转)50道JavaScript基础面试题(附答案)
https://segmentfault.com/a/1190000015288700 1 介绍JavaScript的基本数据类型 Number.String .Boolean .Null.Undef ...
- React Native导航器Navigator
React Native导航器Navigator 使用导航器可以让你在应用的不同场景(页面)间进行切换.导航器通过路由对象来分辨不同的场景.利用renderScene方法,导航栏可以根据指定的路由来渲 ...