大意: n把铲子, 价格1,2,3,...n, 求有多少个二元组(x,y), 满足x+y末尾数字9的个数最多.

枚举最高位, 转化为从[1,n]中选出多少个二元组和为$x$, 枚举较小的数

若$n\ge \lfloor\frac{x}{2}\rfloor$答案为$\lfloor\frac{x}{2}\rfloor$, 否则为$n-\lfloor\frac{x}{2}\rfloor$

#include <iostream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 100;
ll n, tot, f[N], num[N];
int id(int x) {
return num[upper_bound(f+1,f+1+9,x)-f-1];
} int main() {
f[1] = 5;
REP(i,2,9) f[i]=f[i-1]*10;
num[1] = 9;
REP(i,2,9) num[i]=num[i-1]*10+9;
cin>>n, tot = id(n);
if (tot==0) return cout<<n*(n-1)/2<<endl,0;
ll ans = 0;
REP(i,0,9) {
ll num = (ll)i*(tot+1)+tot;
if (n<=num/2) break;
else if (n>=num) ans+=num/2;
else ans+=n-num/2;
}
printf("%lld\n",ans);
}

Shovel Sale CodeForces - 899D (数位dp)的更多相关文章

  1. Codeforces 55D (数位DP+离散化+数论)

    题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. ...

  2. Codeforces 628D 数位dp

    题意:d magic number(0<=d<9)的意思就是一个数,从最高位开始奇数位不是d,偶数位是d 题目问,给a,b,m,d(a<=b,m<2000)问,a,b之间有多少 ...

  3. codeforces 401D (数位DP)

    思路:很明显的数位dp,设dp[i][j] 表示选取数字的状态为i,模m等于j的数的个数,那么最后的答案就是dp[(1<<n)-1][0].状态转移方程就是,dp[i|(1<< ...

  4. Travelling Salesman and Special Numbers CodeForces - 914C (数位dp)

    大意: 对于一个数$x$, 每次操作可将$x$变为$x$二进制中1的个数 定义经过k次操作变为1的数为好数, 求$[1,n]$中有多少个好数 注意到n二进制位最大1000位, 经过一次操作后一定变为1 ...

  5. Codeforces - 914C 数位DP

    题意有点难以描述,简略的就是给定一个二进制\(n\),每一步操作能使\(n\)的位为1的数的和转化为一个十进制,然后转化为该数的二进制再进行相同的操作 查询\([0,n]\)中操作数恰好为\(k\)的 ...

  6. codeforces 55D 数位dp

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  7. codeforces Hill Number 数位dp

    http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits: ...

  8. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces Gym 100231L Intervals 数位DP

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description Start with an integer, N0, ...

随机推荐

  1. ubuntu16.04 backup and restore

    http://blog.csdn.net/qq_35523593/article/details/78545530

  2. 不支持iframe框架?出来吧pdf

    <iframe src='http://km.shengaitcm.com/ADC/_layouts/15/WopiFrame.aspx?sourcedoc=%2FADC%2FDocLib6%2 ...

  3. Zabbix配置网络流量监控报警

    一.SNMP简单概述 1.什么是Snmp SNMP是英文"Simple Network Management Protocol"的缩写,中文意思是"简单网络管理协议&qu ...

  4. GO : 斐波纳契数列

    package main import "fmt" // fibonacci is a function that returns // a function that retur ...

  5. BP神经网络(原理及MATLAB实现)

    人工神经网络概述: 人工神经元模型: 神经网络的分类: 按照连接方式,可以分为:前向神经网络 vs. 反馈(递归)神经网络: 按照学习方式,可以分为:有导师学习神经网络 vs. 无导师学习神经网络: ...

  6. 2019 Lonsdor K518S VS K518ISE

    2019 Lonsdor K518S VS K518ISE: The same: IMMO capabilities + Vehicle coverage. The difference: The u ...

  7. vue环境命令

    1.下载安装note.js用于VUE开发环境 2.VUE项目开发环境安装依赖,命令行进入项目代码目录下执行如下命令npm install 3.开发环境运行npm run dev 4.打包项目npm r ...

  8. JS对象格式化方法:pretty_format

    /* * 格式化 * */ var pretty_format = function (obj, indent) { if (obj === null) return 'null'; if (obj ...

  9. nginx和php-fpm的进程启停重载总结

    nginx和php-fpm对于-USR2.-HUP信号的处理方式不一样: TERM, INT(快速退出,当前的请求不执行完成就退出) QUIT (优雅退出,执行完当前的请求后退出) HUP (重新加载 ...

  10. 评价指标整理:Precision, Recall, F-score, TPR, FPR, TNR, FNR, AUC, Accuracy

    针对二分类的结果,对模型进行评估,通常有以下几种方法: Precision.Recall.F-score(F1-measure)TPR.FPR.TNR.FNR.AUCAccuracy   真实结果 1 ...