当前位置:网站首页>Luogu p1836 number page solution
Luogu p1836 number page solution
2022-07-06 07:29:00 【q779】
Luogu P1836 Page number Answer key
Topic link :P1836 Page number
The question :
The page number of a book is from 1 ∼ n 1\sim n 1∼n Consecutive integer of number : 1 , 2 , 3 , ⋯ , n 1,2,3,\cdots,n 1,2,3,⋯,n. Please find the sum of all the individual numbers in all the pages , For example 123 123 123 page , Its sum is 1 + 2 + 3 = 6 1+2+3=6 1+2+3=6.
1 ≤ n ≤ 1 0 9 1\le n\le 10^9 1≤n≤109
It is easy to find that this thing can be transformed into
1 ∼ n 1 \sim n 1∼n How many numbers are there in each number
Consider digits dp, See link
Then multiply each number by one
Code :
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define N (int)()
int x,mi[25],cnt[25],num[25],f[25];
void solve(int x,int *cnt)
{
int len=0;
memset(num,0,sizeof(num));
while(x)
{
num[++len]=x%10;
x/=10;
}
for(int i=len; i>=1; i--)
{
for(int j=0; j<=9; j++)
cnt[j]+=f[i-1]*num[i];
for(int j=0; j<num[i]; j++)
cnt[j]+=mi[i-1];
int res=0;
for(int j=i-1; j>=1; j--)
{
res = res * 10 + num[j];
}
cnt[num[i]]+=res+1;
cnt[0]-=mi[i-1];
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("check.in","r",stdin);
// freopen("check.out","w",stdout);
mi[0]=1;
for(int i=1; i<=18; i++)
{
f[i]=f[i-1]*10+mi[i-1];
mi[i]=10*mi[i-1];
}
cin >> x;
solve(x,cnt);
int res=0;
for(int i=0; i<=9; i++)
res+=cnt[i]*i;
cout << res << '\n';
return 0;
}
Reprint please explain the source
边栏推荐
- 杰理之如若需要大包发送,需要手机端修改 MTU【篇】
- Cookie Technology & session Technology & ServletContext object
- js对象获取属性的方法(.和[]方式)
- word设置目录
- Simulation of Teman green interferometer based on MATLAB
- Typescript variable scope
- Lesson 12 study notes 2022.02.11
- 成为优秀的TS体操高手 之 TS 类型体操前置知识储备
- CF1036C Classy Numbers 题解
- Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
猜你喜欢
Summary of Digital IC design written examination questions (I)
杰理之BLE【篇】
Path analysis model
Bugku CTF daily question: do you want seeds? Blackmailed
Seriously recommend several machine learning official account
【mysql学习笔记30】锁(非教程)
1091: two or three things in childhood (multi instance test)
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
Oracle column to row -- a field is converted to multiple rows according to the specified separator
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
随机推荐
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
Jerry's ad series MIDI function description [chapter]
jmeter性能测试步骤实战教程
word中如何删除某符号前面或后面所有的文字
Emo diary 1
Seriously recommend several machine learning official account
Twelve rules for naming variables
(4) Web security | penetration testing | network security web site source code and related analysis
Openjudge noi 2.1 1749: Digital Square
Solution to the problem of breakthrough in OWASP juice shop shooting range
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
TS 类型体操 之 循环中的键值判断,as 关键字使用
OpenJudge NOI 2.1 1661:Bomb Game
Simple and understandable high-precision addition in C language
Jerry's general penetration test - do data transmission with app Communication [article]
Crawling exercise: Notice of crawling Henan Agricultural University
Go learning --- use reflection to judge whether the value is valid
qt颜色与字符串、uint相互转换
Fundamentals of C language 9: Functions
Uni app third party package configuration network request