列表

详情


NC216039. 2020

描述

2020 is a special integer, it's formed of two same integers (20 and 20).

We call a number is a good number, if and only if it can be formed of two same integers(without leading zero).

For example: 2020 11, 19991999 are good numbers, but 303, 1122, 1221 are not.

Now you need to count the number of good numbers in

输入描述

The first line has one single integer 


输出描述

Output the answer

示例1

输入:

34

输出:

3

示例2

输入:

111111

输出:

111

示例3

输入:

777776

输出:

776

示例4

输入:

123413454357678

输出:

9999999

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 3ms, 内存消耗: 380K, 提交时间: 2020-12-26 19:55:18

#include<iostream>
using namespace std;
long long n,ans,pw[19];
int s;
int main(){
	cin>>n;
	for(long long i=10;i<=n;i*=10)pw[++s]=i;
	++s;
	if(s&1)cout<<pw[s>>1]-1<<endl;
	else
		cout<<(n/pw[s>>1]<=n%pw[s>>1]?n/pw[s>>1]:n/pw[s>>1]-1)<<endl;
	return 0;
} 

pypy3(pypy3.6.1) 解法, 执行用时: 51ms, 内存消耗: 25536K, 提交时间: 2021-03-12 22:18:09

n = int(input())
l = 1
r = 10 ** 13
while r - l > 1:
	mid = (l + r) // 2
	s = str(mid)
	s = s + s
	if int(s) <= n:
		l = mid
	else:
		r = mid
print(l)

Python3(3.9) 解法, 执行用时: 20ms, 内存消耗: 2816K, 提交时间: 2020-12-26 19:03:57

n = int(input())
l = 1
r = 10 ** 12
while r - l > 1:
	mid = (l + r) // 2
	s = str(mid)
	s = s + s
	if int(s) <= n:
		l = mid
	else:
		r = mid
print(l)

上一题