当前位置:网站首页>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
边栏推荐
- word中把带有某个符号的行全部选中,更改为标题
- QT color is converted to string and uint
- Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
- js对象获取属性的方法(.和[]方式)
- Scala language learning-08-abstract classes
- How are the open source Netease cloud music API projects implemented?
- On the world of NDK (2)
- TS 体操 &(交叉运算) 和 接口的继承的区别
- 杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
- Simulation of Teman green interferometer based on MATLAB
猜你喜欢
JDBC learning notes
Leecode-c language implementation -15 Sum of three ----- ideas to be improved
智能终端设备加密防护的意义和措施
[MySQL learning notes 32] mvcc
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Week6 weekly report
[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps
Excel的相关操作
mysql如何合并数据
杰理之BLE【篇】
随机推荐
洛谷P1836 数页码 题解
OpenJudge NOI 2.1 1749:数字方格
Leecode-c language implementation -15 Sum of three ----- ideas to be improved
Full Score composition generator: living on code
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]
[dictionary tree] [trie] p3879 [tjoi2010] reading comprehension
Méthode d'obtention des propriétés de l'objet JS (.Et [] méthodes)
Force buckle day31
(4) Web security | penetration testing | network security web site source code and related analysis
剪映的相关介绍
word中如何删除某符号前面或后面所有的文字
jmeter性能测试步骤实战教程
JDBC学习笔记
Sharing of source code anti disclosure scheme under burning scenario
杰理之BLE【篇】
Is the super browser a fingerprint browser? How to choose a good super browser?
Jerry's ad series MIDI function description [chapter]
C - Inheritance - hidden method
Résumé de la structure du modèle synthétisable
C # create database connection object SQLite database