Codeforces Round #392 (Div. 2)-758D. Ability To Convert(贪心,细节题)
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 k contains 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.
一个星期不更博了~这场CF我没打,其实是很水的一场,不过这道题解法想到too simple,就是细节特别讨厌,会导致WA声一片。。。
题意:给你N进制与对应的数字,问转化成10进制最小是多少?
解析:一眼贪心,倒着每次尽可能取较多的数,其实证明也是很简单的(略=懒的写),不过要注意前导0问题,细节题啊~最讨厌这种带细节题的场了。DP也可以,可能DP在细节上处理的不会很烦,我这里给出贪心AC代码。
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<utility>
#include<map>
#include<set>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<sstream>
#include<cstring>
#include<bitset>
#include<stack>
using namespace std; long long n,ans;
int l;
string k; long long powx(long long x,int y)
{
if(y==0)return 1;
long long s=powx(x,y/2);
if(y%2)return s*s*x; else return s*s;
} int main()
{
scanf("%I64d",&n);
long long t=n;
while(t>0)
{
t/=10LL;
l++;
}
cin>>k; int p=0,v=0,last=k.size()-1;
long long sum=0;
for(int i=k.size()-1;i>=0;i--)
{
long long t=sum;
sum+=powx(10,v)*(k[i]-48);
if(sum<n && v<l)v++;
else
{
int kkk=i;
if(k[i+1]=='0')
{
int ss=0;
while(k[++i]=='0')
{
ss++;
if(i==last)break;
}
i--;
}
ans+=powx(n,p)*t;
sum=k[i]-48;
v=1;
p++;
last=i;
}
}
ans+=powx(n,p)*sum;
printf("%I64d\n",ans);
return 0;
}
Codeforces Round #392 (Div. 2)-758D. Ability To Convert(贪心,细节题)的更多相关文章
- Codeforces Round #392 (Div. 2)-D. Ability To Convert
D - Ability To Convert 题目大意:给你一个数字 n 接下来再输入一个数字 w(<10^60),表示w这个数字是 n 进制的, 并且超过十进制也用数字表示,这样就有多种组合了 ...
- 【动态规划】Codeforces Round #392 (Div. 2) D. Ability To Convert
D. Ability To Convert time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #392(div 2) 758D (贪心)
orz 最近被水题卡+FST,各种掉rating 题目大意 一个数s它是n进制的,但是每一位不是用'A','B'....表示的,而是用10,11等等表示的,将它还原成十进制 这种表示方法显然会产生多解 ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #392 (Div. 2) F. Geometrical Progression
原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 se ...
- Virtual Codeforces Round #392 (Div. 2)
下午闲来无事开了一场Virtual participation 2h就过了3道水题...又跪了..这只是Div. 2啊!!! 感觉这次直接就是跪在了读题上,T1,T2读题太慢,T3还把题读错了 要是让 ...
- Codeforces Round #392 (Div. 2) - C
题目链接:http://codeforces.com/contest/758/problem/C 题意:给定N*M矩阵的教室,每个位置都有一个学生,Sergei坐在[X,Y],然后老师会问K个问题,对 ...
- Codeforces Round #392 (Div. 2) - B
题目链接:http://codeforces.com/contest/758/problem/B 题意:给定n个点灯的情况,灯只有四种颜色RBGY,然后如果某个灯坏了则用'!'表示,现在要求将坏的灯( ...
随机推荐
- FMDB增删查改
创建,插入,更新和删除:使用executeUpdate方法,而查询则用executeQuery 1.实例化FMDatabase //paths: ios下Document路径,Document为ios ...
- bootstrap建立响应式网站——tab选项卡
1.bootstrap给我们提供了标签页 细细看了一下bootstrap的标签页源码,对tab选项卡有了更深的理解.其实说来也简单,以前自己写js和css时没有意识到整体的划分.就是分为两部分:一部分 ...
- Firefox 插件 JSview是一套比较实用的JS,CSS文件查看工具,很方便,很快捷地查看页面引用了哪些文件,作为Web前端开发者是一套必备的插件,由于Firefox升级过快,插件很快不兼容了,这里对插件做了一些调整,可以兼容最新Firefox浏览器(目前FireFox 21)
JSView Firefox Plugins Download 点击下载
- 好用的消息对话框-TipsWindown
TipsWindow的官网地址为:http://leotheme.cn/javascript/jquery-plugins-tipswindow-2-0.html 这个是一个爱好者维护的!在这里感谢这 ...
- Quick Cocos2dx CCLuaStack has no member names 'loadChunksZip'
demo进行了这么久,已经很久没有连真机调试一下了,昨天下午我旁边的家伙连真机调试出了很多问题,于是我也连真机调一下吧. 运行一下project.android里面的 build_native.bat ...
- [Unity]SQLite-C#调用
SQLite数据库-Unity操作 项目开发的时候,经常会遇到的一种需求,数据存储 离线缓存的数据类型很多,大致分成两类 字符串文本数据 多媒体数据 字符串数据的类型只有字符串,但是结构有很多: xm ...
- HDU 5620 KK's Steel
想了一下发现是斐波那契数列.....水题 #include <stdio.h> #include <algorithm> #include <string.h> # ...
- UVa11555 - Aspen Avenue
今晚CF GYM A题,神坑.. 原题: Aspen Avenue ``Phew, that was the last one!'' exclaimed the garden helper Tim a ...
- Android源码编译jar包BUILD_JAVA_LIBRARY 与BUILD_STATIC_JAVA_LIBRARY的区别(二)
上文简单介绍了BUILD_JAVA_LIBRARY 与BUILD_STATIC_JAVA_LIBRARY编译出来jar包的区别, 那么你如果拿到了一个内容是dex格式的jar包,而你又偏偏需要这个ja ...
- 51驱动LCD12864
LCD12864与LCD1602最大的区别在于LCD12864可以显示汉字,同时也可以拿来画图;当然,作为图形显示不推荐lcd12864,推荐NOKIA5110 12864引脚基本和1602的引脚吻合 ...