当前位置:网站首页>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
边栏推荐
- Related operations of Excel
- Games101 Lesson 7 shading 1 Notes
- After the hot update of uniapp, "mismatched versions may cause application exceptions" causes and Solutions
- Full Score composition generator: living on code
- Uni app third party package configuration network request
- TS 类型体操 之 extends,Equal,Alike 使用场景和实现对比
- 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
- 杰理之AD 系列 MIDI 功能说明【篇】
- Select all the lines with a symbol in word and change them to titles
- Path analysis model
猜你喜欢
The way to learn go (I) the basic introduction of go to the first HelloWorld
NiO programming introduction
Mise en œuvre du langage leecode - C - 15. Somme des trois chiffres - - - - - idées à améliorer
ORACLE列转行--某字段按指定分隔符转多行
First knowledge of OpenGL es learning (1)
[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps
1091: two or three things in childhood (multi instance test)
软件测试界的三无简历,企业拿什么来招聘你,石沉大海的简历
Week6 weekly report
Path analysis model
随机推荐
GET/POST/PUT/PATCH/DELETE含义
杰理之需要修改 gatt 的 profile 定义【篇】
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
qt颜色与字符串、uint相互转换
On the world of NDK (2)
Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
Uni app third party package configuration network request
Is the super browser a fingerprint browser? How to choose a good super browser?
Scala language learning-08-abstract classes
navicat如何导入MySQL脚本
[CF Gym101196-I] Waif Until Dark 网络最大流
智能终端设备加密防护的意义和措施
Select all the lines with a symbol in word and change them to titles
位运算异或
Structure summary of SystemVerilog integrable model
[dictionary tree] [trie] p3879 [tjoi2010] reading comprehension
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]
Typescript variable scope
多线程和并发编程(二)
[MySQL learning notes 30] lock (non tutorial)