Codeforces-758D Ability To Convert

传送门

给定一个N,和一个字符串,已知字符串是由不大于N的十进制数拼接而成,从左到右分别代表N^k, N^(k-1)...., N^1, N^0的权数,求这个字符串代表的数的最小值

嗯 注意前导零

 1 #include <cmath>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <queue>
 7 #define INF 0x3f3f3f3f
 8 using namespace std;
 9 typedef long long LL;
10 LL N, M;
11 LL ans;
12 const int maxk = 66;
13 string s;
14 string ss;
15
16 void add(int i, int j) {
17     LL tmp = 0;
18     for (int k = i; k <= j; k++) {
19         tmp = tmp * 10 + s[k] - ‘0‘;
20     }
21     ans = ans + tmp * M;
22 }
23
24 int main() {
25     LL tmp = 0;
26     cin >> ss;
27     int l = ss.length();
28     for (int i = 0 ; i <= l - 1; i++) {
29         N = N * 10 + ss[i] - ‘0‘;
30     }
31     M = 1;
32     cin >> s;
33     int len = s.length();
34     for (int i = len - 1; i >= 0; i -= l) {
35         if (i >= l - 1) {
36             int k;
37             if (s.substr(i - l + 1, l) >= ss) {
38                 add(i - l + 2, i);
39                 k = i - l + 2;
40             } else {
41                 add(i - l + 1, i);
42                 k = i - l + 1;
43             }
44             while (k <= i && s[k] == ‘0‘) {
45                 k++;
46             }
47             if (k == i + 1) {
48                 i = i + l - 1;
49             } else {
50                 i = k + l - 1;
51             }
52         } else {
53             add(0, i);
54         }
55         M *= N;
56     }
57     printf("%lld\n", ans);
58     return 0;
59 }
时间: 2024-08-28 07:24:18

Codeforces-758D Ability To Convert的相关文章

Codeforces 758D Ability To Convert dp

题目链接: http://codeforces.com/problemset/problem/758/D 题意: 一个n进制下的数k,其中k不会用字母,如果有A就用10代替了.求k这个数对应的,在10进制下最小的数. 思路: 来自:http://www.cnblogs.com/TreeDream/p/6322755.html 本质上是把数字分成若干段使得每一段 <n 且没有前导 0 dp[i] 表示前 i 个字符划分好之后能得到的最小数. 状态枚举下一段怎么切. 枚举每一个分割点,对什么进行更新

Codeforces 758D Ability To Convert(区间DP)

题目链接:http://codeforces.com/problemset/problem/758/D 题意:一个n进制下的数k,其中k不会用字母,如果有A就用10代替了.求k这个数对应的,在10进制下最小的数. 分析: 本质上是把数字分成若干段使得每一段 <n 且没有前导 0 dp[i] 表示前 i 个字符划分好之后能得到的最小数. 状态枚举下一段怎么切. 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdli

cf 758D - Ability To Convert

从后往前贪心就好了.各种各样0的情况太BT了.. (各种爆long long,f**k) 1 #include<bits/stdc++.h> 2 #define LL long long 3 #define N 100005 4 #define lowbit(x) x&(-x) 5 using namespace std; 6 inline int ra() 7 { 8 int x=0,f=1; char ch=getchar(); 9 while (ch<'0' || ch&g

CodeForces 758 D Ability To Convert

Ability To Convert 题意:给你一个n进制的60位的数,但是由于Alexander只会写0->9,所以他就会用10来表示十而不是A(假设进制>10); 题解:模拟就好了,先走往前走进制的位数的倍数,再判断一下首位是不是0,或者这个数有没有大于等于进制,如果有就不行,就要往后走,走到一个非0开头的点,或者就是走到只有1个0的点,然后算出目前这段区间的答案加一个倍数就好了. 代码: 1 #include<bits/stdc++.h> 2 using namespace

Codeforces Round #392 (Div. 2)

A - Holiday Of Equality(water) 题意:一共给你N个数,让你向上补数值,使得最终所有数值都相等,输出最少花费. 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int INF = 0x3f3f3f3f; 5 const int maxn = 100 + 5; 6 7 int a[maxn]; 8 9 int main() 10 { 11 int n;

business knowledge

Finance knowledge Trading---At the core of our business model is Trading, which involves the buying and selling of financial tools to generate profit. Trading takes place in our Global Markets division, which spans collateralised financing, commoditi

卷积神经网络用于视觉识别Convolutional Neural Networks for Visual Recognition

Table of Contents: Architecture Overview ConvNet Layers Convolutional Layer Pooling Layer Normalization Layer Fully-Connected Layer Converting Fully-Connected Layers to Convolutional Layers ConvNet Architectures Layer Patterns Layer Sizing Patterns C

VCFtools

The C++ executable module examples This page provides usage examples for the executable module. Extended documentation for all of the options can be found on the manual page. Running the program Getting basic file statistics Applying a filter Writing

PatentTips - Safe general purpose virtual machine computing system

BACKGROUND OF THE INVENTION The present invention relates to virtual machine implementations, and in particular to a safe general purpose virtual machine that generates optimized virtual machine computer programs that are executable in a general purp