A. Boring Apartments(水题) Codeforces Round #677 (Div. 3)

Link to the original question: https://codeforces.com/contest/1433/problem/A

Insert picture description here
Test sample

input
4
22
9999
1
777
output
13
90
1
66

Question meaning: there are 10000 100001 0 0 0 0 apartments, numbered from1 11 to10000 100001 0 0 0 0 , now there is a particularly boring one. He will dial the apartment number of the apartment with the same number and will not stop until someone answers the call. The dialing sequence is increasing, namely:1 −> 11 −> 111 −> 1111 − > 2 −> 22... 1->11->111->1111->2->22...1>11>111>1111>2>2 2 . . . . Now give the number of the household who answered the phone, and ask this bored person how many times he pressed the number.

Problem-solving idea: This problem is a water problem. Since the number of answering households is given, and we find that the numbers on these numbers are the same, it is actually more convenient for us to store them in strings. (You can directly get the length and the number on the number.) Then we can solve this problem through simple formula derivation. Let the length be len lenl e n , the number on the number isaaa . Then a total of(1 + 2 + 3 + 4) × (a − 1) + (len + 1) × len / 2 (1+2+3+4)\times (a-1)+(len+1 )\times len/2(1+2+3+4)×(a1)+( l e n+1)×l e n / 2

AC code

/*
*邮箱:[email protected]
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>	//POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t;
string s;
int main(){
    
    
	//freopen("in.txt", "r", stdin);//提交的时候要注释掉
	IOS;
	while(cin>>t){
    
    
		while(t--){
    
    
			cin>>s;
			int len=s.size();
			int temp=s[0]-'0';
			cout<<10*(temp-1)+(1+len)*len/2<<endl;
		}
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/hzf0701/article/details/109192905