【Codeforces Round #452 (Div. 2) D】Shovel Sale
【链接】 我是链接,点我呀:)
【题意】
【题解】
让N乘2->a 然后看一下位数是多少。 假设有x位(x>=2) 则(0..(a%10-1) ) + (99..9)[x-1个]都是合法的转化为1..N里面有多少对,它们的和为x
x总是为奇数
若x-1<=n
先减去1
1 ... x-1
x-1为偶数
1..4
答案为4/2
若x-1>n
则让temp = x-n;
如果temp<n
则temp + n是等于x的
同时temp+1 + n-1也是等于x的
。。
对于组合不出9的情况
输出所有对数即可。
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
string s;
ll Change(string temp){
ll now = 0;
for (int i = 0;i < (int) temp.size();i++){
now = now*10+temp[i]-'0';
}
return now;
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
if (2*n <= 9){
int ans1 = 0,ans2 = 0;
for(int i = 1;i <= n;i++)
for (int j = i+1;j <= n;j++){
if ((i+j)==9){
ans1++;
}
ans2++;
}
if (ans1==0){
cout << ans2 << endl;
}else
cout << ans1 << endl;
}else{
ll ans2 = 0;
ll temp = n*2;
s = "";
while (temp>0){
s = ((char)(temp%10+'0')) + s;
temp/=10;
}
int len = s.size();
for (int i = 1;i <= len-1;i++) s[i] = '9';
s[0]--;
while (s[0]>='0'){
ll x = Change(s);
if (x-1<=n){
ans2 += (x-1)/2;
}else{//x-1>n
ll temp = x-n;
if (temp < n){
ll l = temp,r = n;
ll len = (r-l+1);
ans2+=len/2;
}
}
s[0]--;
}
cout << ans2 << endl;
}
return 0;
}