codeforces Div.2 899D Shovel Sale
来源:互联网 发布:nature数据库使用 编辑:程序博客网 时间:2024/06/05 02:30
大意:
给出一个数 n
求 1<= a , b <= n , 记 N = a +b
求末尾有最多连续的9的N,a,b 有多少(无序)组。两组是不同的当且仅当 有一个数不同。
样例解释:
input
14
output
9
hint:
In the example the maximum number of nines at the end of total cost of two shovels is one. :
1 and 8;
2 and 7;
3 and 6;
4 and 5;
5 and 14;
6 and 13;
7 and 12;
8 and 11;
9 and 10.
思路:
一个n确定的最多的连续的9数字是可以确定的,比如 n=300 可以确定构造出
枚举x,并计数,就是答案。
对于一个数如
如果是,那么考虑构造
否则
枚举 x = 0->8
对于A 的种数为
1 A-12 A-2...(A-1)/2 (A+1)/2
共 (A-1)/2 种,但是受 n 的限制,可能取不到值
n 的区间为
(A+1)/2 <= n <=A-1
n>=A
n<(A+1)/2
三种情况分别计数即可。
ps. 0个9结尾也算
实现代码:
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair <int,int> pii;#define mem(s,t) memset(s,t,sizeof(s))#define D(v) cout<<#v<<" "<<v<<endl#define inf 0x3f3f3f3f#define pb push_back//#define LOCALconst int mod=1e9+7;const int MAXN =1e5+10;int main() { ll n,N; cin>>n; if(n<5){ cout<<(n-1)*n/2<<endl; return 0; } ll a[15],b[15]; a[0]=b[0]=1; a[1]=10,b[1]=9; for(int i=2;i<=12;i++){ a[i]=a[i-1]*10; b[i]=b[i-1]*10+9; } N=n; int cnt=0; while(N){ N/=10; cnt++; } ll ans=0; if(n>=5*a[cnt-1]){ cnt++; } for(int i=0;i<=8;i++){ ll A=i*a[cnt-1]+b[cnt-1]; if((A+1)/2<=n && n<=A-1){ ans+=n-(A+1)/2+1; } else if(n>=A){ ans+=(A-1)/2; } } cout<<ans<<endl; return 0;}
阅读全文
0 0
- codeforces Div.2 899D Shovel Sale
- codeforces 899D. Shovel Sale
- Codeforces 899D Shovel Sale
- Codeforces Round #452 (Div. 2) D. Shovel Sale
- codeforces——D. Shovel Sale
- Codeforces Round #377 (Div. 2) A. Buy a Shovel
- Codeforces899D Shovel Sale
- CF 899D Shovel Sell 思维.
- codeforces #354(div 2) D
- Codeforces Round #103 (Div. 2) D
- Codeforces Round #104 (Div. 2) D
- Codeforces Round #105 (Div. 2) D
- Codeforces Round #139 (Div. 2) D. Snake
- Codeforces Round #155 (Div. 2) D-rats
- Codeforces Round #159 (Div. 2) D sum
- Codeforces 182 Div.2 D题
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round#186(Div 2) D
- 我的Java学习第一本书
- jsp基础大全
- 非常好的一篇对linux信号(signal)的解析 (转载)
- Mysql按照in的顺序展示
- 又思考如何成为一个技术大牛
- codeforces Div.2 899D Shovel Sale
- 插入查询操作
- Kotlin之字符串模板
- cocos2dx游戏中添加背景音乐、音效
- TeamViewer破解试用期(已过试用期)
- tensorflow处理自己的图像数据(不使用队列)
- YUV的一个不错的网站
- UITableView显示默认分割线左边部分缺少显示问题解决
- MySQL字符串函数substring:字符串截取