# AtCoder Beginner Contest 155 E.Payment

In the Kingdom of AtCoder, only banknotes are used as currency. There are
10100+110^{100}+1

What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?

Assume that you have sufficient numbers of banknotes, and so does the clerk.

Constraints N is an integer between 1 and 101,000,00010^{1,000,000}

## Input

Input is given from Standard Input in the following format:

N

• 1

## Output

Print the minimum possible number of total banknotes used by you and the clerk.

## Sample Input 1

36

• 1

## Sample Output 1

8

• 1

## Sample Input 2

91

• 1

## Sample Output 2

3

• 1

## Sample Input 3

314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170

• 1

## Sample Output 3

243题意：

1,000,000（含）。

1.x 小于5，则答案直接加上 x
2.x 大于5，则答案直接加上 10−x
3.比较难考虑的就是 x=5 的情况，你说四舍五入，那么假设 n=5 时就不对，你如果进位的话就是一共付了6张，正确答案是5张；你说不进，那么假设 n=995，你进位后就是 1005，一共付了7张，正确答案是6张。通过我的举例你不难发现，x=5要进位只需它的前一位大于等于5即可

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<cstring>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int maxn=2e5+10;
const int mod =1e9+7;
const double EPS = 1e-6;

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
s='0'+s;
ll ans=0;
for(int i=s.size()-1;i>=1;i--)
{
if(s[i]>'5')
{
ans+=10-(s[i]-'0');
s[i-1]++;
}
else if(s[i]=='5'&&s[i-1]>='5')
{
ans+=10-(s[i]-'0');
s[i-1]++;
}
else
{
ans+=(s[i]-'0');
}
}
if(s[0]!='0')
ans++;
cout << ans << endl;
return 0;
}

posted @ 2020-02-17 23:31  晴天要下雨  阅读(...)  评论(...编辑  收藏