codeforces 758D
1 second
256 megabytes
standard input
standard output
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475 = 1·162 + 13·161 + 11·160). Alexander lived calmly until he tried to convert the number back to the decimal number system.
Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k.
The first line contains the integer n (2 ≤ n ≤ 109). The second line contains the integer k (0 ≤ k < 1060), it is guaranteed that the number kcontains no more than 60 symbols. All digits in the second line are strictly less than n.
Alexander guarantees that the answer exists and does not exceed 1018.
The number k doesn't contain leading zeros.
Print the number x (0 ≤ x ≤ 1018) — the answer to the problem.
13
12
12
16
11311
475
20
999
3789
17
2016
594
In the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·130 or 15 = 1·131 + 2·130.
这题的题意是第一行输入一个进制,第二行输入该进制下的数,输出将该数转化为十进制的最小值。
( 有零的地方一直都处理不好- -,后来看了别人的代码才学会。
思路是用字符串读入,从后往前加,如果大于输入的进制了,就跳出再判断含有0的情况,直到循环到起始。
1 #include <iostream>
2 #define ll long long
3 using namespace std;
4 string s;
5 int main()
6 {
7 ll b;
8 cin>>b>>s;
9 ll ans = 0;
10 ll p = 1;
11 ll len = s.length() - 1;
12 while(len >= 0) {
13 ll sum = 0;
14 ll t = 1;
15 ll i;
16 for( i = len; i >= 0; i--) {
17 if(max((s[i] - '0'),1) * t + sum >= b)
18 break;
19 sum += (s[i] - '0') * t;
20 t *= 10;
21 // cout<<sum<<endl;
22 }
23 while(i < len - 1) { //每位至少有一个数,所以每次大的循环至少会让最后一位数
24 if(s[i+1] == '0') { //加入ans中,因此遍历到倒数第二位之前就行了
25 i++;
26 }
27 else break;
28 }
29 ans += sum * p;
30 // cout<<ans<<endl;
31 p *= b;
32 len = i;
33 }
34 cout << ans << endl;
35 return 0;
36 }
codeforces 758D的更多相关文章
- Codeforces 758D Ability To Convert(区间DP)
题目链接:http://codeforces.com/problemset/problem/758/D 题意:一个n进制下的数k,其中k不会用字母,如果有A就用10代替了.求k这个数对应的,在10进制 ...
- 【codeforces 758D】Ability To Convert
[题目链接]:http://codeforces.com/contest/758/problem/D [题意] 给你一个n进制的数k; 问你它可能的最小的十进制数是多少; [题解] 从右往左; 获取数 ...
- Codeforces 758D:Ability To Convert(思维+模拟)
http://codeforces.com/problemset/problem/758/D 题意:给出一个进制数n,还有一个数k表示在n进制下的值,求将这个数转为十进制最小可以是多少. 思路:模拟着 ...
- codeforces 758D Ability To Convert【DP】
在N进制下给你一个数,要你转换成最小的十进制数; 状态转移方程:从前向后 dp[j]表示j位前数列的最小十进制数 dp[j]=min(dp[j],dp[i]*n+x) 程序: #include < ...
- Codeforces Round #392 (Div. 2)-758D. Ability To Convert(贪心,细节题)
D. Ability To Convert time limit per test 1 second Cmemory limit per test 256 megabytes input standa ...
- Codeforces Round #392(div 2) 758D (贪心)
orz 最近被水题卡+FST,各种掉rating 题目大意 一个数s它是n进制的,但是每一位不是用'A','B'....表示的,而是用10,11等等表示的,将它还原成十进制 这种表示方法显然会产生多解 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- kernel升级模式RKS让人振奋
前几天刚将我的ERP内核从701_rel 升级到721_ext_rel,看到721的说明了讲到,对于这次的更新,支持RKS(Rolling Kernel Switch)了,简单的讲,就是以后对于内核的 ...
- 都知道Base64,Base32你能实现吗?
很长时间没有更新个人博客了,因为前一段时间在换工作,入职了一家新的公司,刚开始需要适应一下新公司的节奏,开始阶段也比较忙.新公司还是有一定的技术气氛的,每周都会有技术分享,而且还会给大家留一些思考题, ...
- wordpress迁移报错
背景: 因为一些原因迁移wordpress的博客.备份好数据库和网站源码到另一台生产环境上线的时候报错: Warning: require(/www/wwwroot/pazzn/wp-includes ...
- 在Sublime Text 2工具下编辑laravel框架
介绍Sublime编辑器 Sublime Text 3官方版是Sublime Text2的升级版.Sublime Text是一款流行的文本编辑器软件,有点类似于TextMate,跨平台,可运行在Lin ...
- Wireshark抓包参数
目录 wireshark 抓包过滤器 一.抓包过滤器 二.显示过滤器 整理自陈鑫杰老师的wireshark教程课 wireshark 抓包过滤器 过滤器分为抓包过滤器和显示过滤器,抓包过滤器会将不满足 ...
- 【算法】深度优先搜索(dfs)
突然发现机房里有很多人不会暴搜(dfs),所以写一篇他们能听得懂的博客(大概?) PS:万能 yuechi ---- 大法师怎么能不会呢?! 若有错误,请 dalao 指出. 前置 我知道即使很多人都 ...
- luogu p2622
题目描述 现有n盏灯,以及m个按钮.每个按钮可以同时控制这n盏灯--按下了第i个按钮,对于所有的灯都有一个效果.按下i按钮对于第j盏灯,是下面3中效果之一:如果a[i][j]为1,那么当这盏灯开了的时 ...
- Spring Boot配置,读取配置文件
Spring Boot配置,读取配置文件 一.配置Spring Boot 1.1 服务器配置 1.2 使用其他Web服务器 1.3 配置启动信息 1.4 配置浏览器显示ico 1.5 Yaml语法 1 ...
- ACM-古老的密码(排序qsort)
古老的密码 题目描述:给定两个长度一样且不超过100的字符串,判断是否能把其中一个字符串的各个字母重排,之后对26个字母做一个一一映射,使得两个字符串相同例如,JWPUDJSTVP重排后可以得到WJD ...
- CyclicBarrier---可重用的循环栅栏
很多文章只是提了下可重用,具体这个栅栏怎么可重用的,很多没有说明,这里会解开你的疑惑. CyclicBarrier是一个同步工具类,它允许一组线程互相等待,直到达到某个公共屏障点.与CountDown ...