AtCoder2341 - Increasing Numbers - 二分+思维
2017-05-24 17:55
471 查看
1.题目描述:
Time limit : 2sec / Memory limit : 256MB
Score : 1300 points
For example, 1558, 11, 3 and 0 are
all increasing; 10 and 20170312 are
not.
Snuke has an integer N.
Find the minimum number of increasing integers that can represent N as their sum.
their sum.
One possible representation is 80=77+3.
123456789 in itself is increasing,
and thus it can be represented as the sum of one increasing integer.
2.题意概述:
当一个整数高位数字总不小于低位数字,或者说写成字符串之后单调不下降,称之为上升数。求一个整数最少能表示为多少个上升数的和。
3.解题思路:
4.AC代码:
E - Increasing Numbers
Time limit : 2sec / Memory limit : 256MBScore : 1300 points
Problem Statement
We will call a non-negative integer increasing if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left.For example, 1558, 11, 3 and 0 are
all increasing; 10 and 20170312 are
not.
Snuke has an integer N.
Find the minimum number of increasing integers that can represent N as their sum.
Constraints
1≤N≤10500000Input
The input is given from Standard Input in the following format:N
Output
Print the minimum number of increasing integers that can represent N astheir sum.
Sample Input 1
Copy80
Sample Output 1
Copy2
One possible representation is 80=77+3.
Sample Input 2
Copy123456789
Sample Output 2
Copy1
123456789 in itself is increasing,
and thus it can be represented as the sum of one increasing integer.
Sample Input 3
Copy20170312
Sample Output 3
Copy4
Sample Input 4
Copy7204647845201772120166980358816078279571541735614841625060678056933503
Sample Output 4
Copy31
2.题意概述:
当一个整数高位数字总不小于低位数字,或者说写成字符串之后单调不下降,称之为上升数。求一个整数最少能表示为多少个上升数的和。
3.解题思路:
4.AC代码:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 500100
#define lson root << 1#define rson root << 1 | 1#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
char s[maxn];
int a[maxn];
int len;
bool check(int x)
{
int sum = x * 9, cnt = 0;
for (int i = 0; i < len; i++)
{
sum += a[i];
cnt += sum % 10;
sum /= 10;
}
while (sum > 0)
{
cnt += sum % 10;
sum /= 10;
}
return cnt <= x * 9;
}
int main()
{
while (~scanf("%s", s))
{
memset(a, 0, sizeof(a));
len = strlen(s);
reverse(s, s + len);
for (int i = 0; i < len; i++)
a[i] = (s[i] - '0') * 9;
for (int i = 0; i < len; i++)
{
a[i + 1] += a[i] / 10;
a[i] %= 10;
}
if (a[len])
len++;
int l = 0, r = len * 2, ans = -1;
while (l < r)
{
int mid = l + r >> 1;
if (check(mid))
{
ans = mid;
r = mid;
}
else
l = mid + 1;
}
printf("%d\n", ans);
}
return 0;
}
相关文章推荐
- Codeforces 344E Read Time [二分答案]【思维】
- Atcoder:TrBBnsformBBtion(思维 & 字符串)
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 思维排序或二分
- Codeforces 672D Robin Hood【思维+二分】这题思路有点劲啊
- UVALive 6694 - Toy Boxes(思维+二分)
- HDU 4343 多查询求区间内的最大不相交区间个数-思维&贪心-卡时间&二分&剪枝
- 51nod oj 1305 Pairwise Sum and Divide 【思维-组合-二分查找】
- CF#348 A. Mafia(二分,思维)
- CF EDU 40 C, D, G 题解 【思维,图论,二分】
- ZOJ 1654 Place the Robots建图思维(分块思想)+二分匹配
- Codeforces 387D George and Interesting Graph【思维+二分匹配】
- Codeforces 864D D. Make a Permutation!【思维+线段树+二分+这是一个煞笔做法】
- CF - 808D. Array Division - 二分+暴力+前缀和思维
- 51nod 1557 两个集合 (二分搜索,思维逻辑好题)
- AtCoder Beginner Contest 081 D - Non-decreasing 【思维移位】
- Codeforces 551C GukiZ hates Boxes【二分+思维处理】好题!
- HDU-1597-find the nth digit(二分+思维)
- POJ2976 - Dropping tests - 二分+01分数规划+思维
- Codeforces 782B The Meeting Place Cannot Be Changed【二分+思维】
- 【算法】二分查找——与答案进行比较的思维