【题目链接】: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的更多相关文章

  1. Codeforces 758D:Ability To Convert(思维+模拟)

    http://codeforces.com/problemset/problem/758/D 题意:给出一个进制数n,还有一个数k表示在n进制下的值,求将这个数转为十进制最小可以是多少. 思路:模拟着 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. uboot的GPIO驱动分析--基于全志的A10芯片【转】

    本文转载自:http://blog.csdn.net/lw2011cg/article/details/68954707 uboot的GPIO驱动分析--基于全志的A10芯片 转载至:http://b ...

  2. Python中操作myslq的方法

    实例1.取得MYSQL的版本 在windows环境下安装mysql模块用于python开发,请见我的另一篇文章: MySQL-python Windows下EXE安装文件下载 # -*- coding ...

  3. openstack instance resize to

    Icehouse resize No valid host was found Hi all!! We're currently experimenting an error that's it's ...

  4. sizeof中的表达式不执行

    char a = 255;      printf("%d\n",a);    printf("%d\n",sizeof(++a));      printf( ...

  5. P3299 [SDOI2013]保护出题人

    传送门 全世界都会二分可海星-- 首先记\(sum[i]\)为\(a[i]\)的前缀和,那么第\(i\)个的答案就是\(max\{\frac{sum[i]-sum[j-1]}{x+(i-j)d}\}\ ...

  6. Netty(2) - HelloWorld

    Netty:作用场景. 1)Netty可以基于socket实现远程过程调用(RPC). 2)Netty可以基于WebSocket实现长连接. 3)Netty可以实现Http的服务器,类似于Jetty, ...

  7. NS2学习笔记(四)

    这几天学习NS2,虽然国内很多人使用,但系统的教材资料不多,只能一边看中文教材,一边看英文手册,知识点也是零零散散.过段时间等能将所有知识点串上,再总结总结.现只讲一些零碎的点记录一下. 添加新的协议 ...

  8. 1、Web MVC简介

  9. post提交表单的数据查看方式(不是很理解,但要会看,可以找人商讨下,比如崔老师,自己再看一遍HTTP基础)

  10. 这辈子写过的比较有意思的几个sql

    递归 with myRecursion as( select * from recursion where id=1 union all select r.* from myRecursion m,r ...