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>‘9‘) {if (ch==‘-‘) f=-1; ch=getchar();}
10     while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();}
11     return x*f;
12 }
13 LL n,m=1,ans;
14 string s;
15 LL get(int l, int r)// int boom!!
16 {
17     LL sum=0;
18     for (int i=l; i<=r; i++)
19     {
20         sum=sum*10+s[i]-‘0‘;
21         if (sum>n) break;
22     }
23     return sum;
24 }
25 int main()
26 {
27     n=(LL)ra(); cin>>s;
28     int len=s.length();
29     int last=len-1,i=len-1;
30     while (i!=-1)
31     {
32         if (s[i]!=‘0‘ && get(i,last)<n)
33         {
34             i--;
35             if (i==-1)
36             {
37                 ans+=m*get(0,last);
38                 break;
39             }
40             continue;
41         }
42         if (s[i]==‘0‘)
43         {
44             int j=i;
45             while (j!=-1 && get(j,last)<n && s[j]==‘0‘) j--;
46             while (s[last]==‘0‘ && get(j,last)>=n) m=m*n,last--;
47             if (s[j]!=‘0‘ && get(j,last)<n) i=j;
48             if (s[j]!=‘0‘ && get(j,last)>=n)
49             {
50                 ans+=m*get(i,last);
51                 last=i;
52                 m=m*n;
53             }
54         }
55         if (s[i]!=‘0‘ && get(i,last)>=n)
56         {
57             ans+=m*get(i+1,last);
58             last=i;
59             m*=n;
60         }
61     }
62     cout<<ans;
63     return 0;
64 }
时间: 2024-12-15 06:52:08

cf 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

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-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&

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