http://codeforces.com/problemset/problem/758/D

题意:给出一个进制数n,还有一个数k表示在n进制下的值,求将这个数转为十进制最小可以是多少。

思路:模拟着做,有点像two-pointer的做法。正着扫这个字符串,如果找到一个符合题意的即比n小的数,那么这个数是合法的,可以加上,接下来下标就移动到扫到的位置-1。主要难点我觉得在于0的时候的情况,如果当前的下标指的位置是0的话,无疑这个0是对当前的数是没有贡献的,那么这一位0应该不算上去,指针应该向后找非0的直到边界。

 #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
using namespace std;
#define INF 0x3f3f3f3f
#define N 100010
typedef long long LL;
char s[]; int main() {
LL base;
cin >> base >> s;
int len = strlen(s);
LL ans = , mul = , tmp;
int st, ed = len - ;
while(ed >= ) {
st = ;
for(int i = ; i <= ed; i++) {
if(ed - i > ) continue; // 如果太大会爆LL
tmp = ;
for(int j = i; j <= ed; j++)
tmp = tmp * + s[j] - '';
if(tmp < base) { st = i; break; } // 找到合适的数
}
while(st < ed && s[st] == '') st++;
ans = ans + mul * tmp; mul = mul * base; ed = st - ;
}
cout << ans << endl;
return ;
}
/*
17
202016
*/

Codeforces 758D:Ability To Convert(思维+模拟)的更多相关文章

  1. Codeforces 758D Ability To Convert(区间DP)

    题目链接:http://codeforces.com/problemset/problem/758/D 题意:一个n进制下的数k,其中k不会用字母,如果有A就用10代替了.求k这个数对应的,在10进制 ...

  2. codeforces 758D Ability To Convert【DP】

    在N进制下给你一个数,要你转换成最小的十进制数; 状态转移方程:从前向后 dp[j]表示j位前数列的最小十进制数 dp[j]=min(dp[j],dp[i]*n+x) 程序: #include < ...

  3. 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 ...

  4. CF--思维练习--CodeForces - 216C - Hiring Staff (思维+模拟)

    ACM思维题训练集合 A new Berland businessman Vitaly is going to open a household appliances' store. All he's ...

  5. 【Codeforces】879D. Teams Formation 思维+模拟

    题意 给定$n$个数,重复拼接$m$次,相邻$k$个重复的可消除,问最后序列中有多少个数 首先可以发现当$k>=n$时,如果要使$n$个数可以被消除,那么$n$个数必须一样,否则$n$个数不能被 ...

  6. cf 758D - Ability To Convert

    从后往前贪心就好了.各种各样0的情况太BT了.. (各种爆long long,f**k) #include<bits/stdc++.h> #define LL long long #def ...

  7. CodeForces 758 D Ability To Convert

    Ability To Convert 题意:给你一个n进制的60位的数,但是由于Alexander只会写0->9,所以他就会用10来表示十而不是A(假设进制>10); 题解:模拟就好了,先 ...

  8. Codeforces Round #392 (Div. 2)-D. Ability To Convert

    D - Ability To Convert 题目大意:给你一个数字 n 接下来再输入一个数字 w(<10^60),表示w这个数字是 n 进制的, 并且超过十进制也用数字表示,这样就有多种组合了 ...

  9. 【动态规划】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 ...

  10. D. Ability To Convert

    http://codeforces.com/contest/758/problem/D D. Ability To Convert time limit per test 1 second memor ...

随机推荐

  1. Easyui Tab刷新

    Easyui Tab刷新: function refreshTab(title){ var tab = $('#id').tab('getTab',title); $('#id').tab('upda ...

  2. thinkphp 删除所有缓存 Rumtime 以及 Html 静态缓存

    <?php /** * This is not a free software, All Copyright @F.Z.B * Date: 14-8-12 下午4:08 * File: Cach ...

  3. .net core注入服务

    1.在Startup的ConfigureServices里面,通过IServiceCollection进行注入 public void ConfigureServices(IServiceCollec ...

  4. ios7 获取UITablleViewCell

    iOS7之前UITablleViewCell中得contentView得superView就是UITableViewCell.但是在iOS7得时候,contentView得superView确实UIT ...

  5. WPF 自定义范围分组

    <Window x:Class="ViewExam.MainWindow"        xmlns="http://schemas.microsoft.com/w ...

  6. WPF DataGrid自动生成列

    <Window x:Class="DataGridExam.MainWindow"        xmlns="http://schemas.microsoft.c ...

  7. DevExpress XtraTreeList TreeList复选框选择

    权限管理涉及复选框多勾选. 1.控件属性设置 TreeList.OperationView.ShowCheckBoxes=true;用于显示CheckBox: TreeList.OperationBe ...

  8. C#基础加强篇---委托、Lamada表达式和事件(中)

    2.Lamada表达式     C#共有两种匿名函数:匿名方法和Lamada表达式.在2.0之前的C#版本中,创建委托的唯一方法是使用命名方法.C#2.0中引入了匿名方法,匿名方法就是没有名称的方法. ...

  9. 微信小程序把玩(二十五)loading组件

    原文:微信小程序把玩(二十五)loading组件 loading通常使用在请求网络数据时的一种方式,通过hidden属性设置显示与否 主要属性: wxml <!----> <butt ...

  10. ML:吴恩达 机器学习 课程笔记(Week9~10)

    Anomaly Detection Recommender Systems Large Scale Machine Learning