当前位置:网站首页>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
边栏推荐
- 1091: two or three things in childhood (multi instance test)
- [JDBC] quick start tutorial
- Ble of Jerry [chapter]
- Scala language learning-08-abstract classes
- word删除括号里内容
- 超级浏览器是指纹浏览器吗?怎样选择一款好的超级浏览器?
- Supervisor usage document
- QT color is converted to string and uint
- Word setting directory
- Résumé de la structure du modèle synthétisable
猜你喜欢
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
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
[MySQL learning notes 30] lock (non tutorial)
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]
[CF Gym101196-I] Waif Until Dark 网络最大流
剪映的相关介绍
leecode-C语言实现-15. 三数之和------思路待改进版
Force buckle day31
Markdown 中设置图片图注
Seriously recommend several machine learning official account
随机推荐
word怎么只删除英语保留汉语或删除汉语保留英文
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
leecode-C語言實現-15. 三數之和------思路待改進版
Multithreading and concurrent programming (2)
How to configure GUI guide development environment
How Navicat imports MySQL scripts
GET/POST/PUT/PATCH/DELETE含义
Uni app practical project
Cookie Technology & session Technology & ServletContext object
Three treasures of leeks and Chinese men's football team
JDBC learning notes
【mysql学习笔记30】锁(非教程)
【MySQL学习笔记32】mvcc
Rust language - receive command line parameter instances
Force buckle day31
Seriously recommend several machine learning official account
Crawling exercise: Notice of crawling Henan Agricultural University
C - Inheritance - polymorphism - virtual function member (lower)
Mise en œuvre du langage leecode - C - 15. Somme des trois chiffres - - - - - idées à améliorer
Week6 weekly report