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

it2025-03-19  12

题意: 一个人打电话,按照1 11 111 1111 2 22 222 2222 3 33 333。。。的顺序打电话一直打到9999. 给一个停止的数字,问到这个数字为止,总共按了多少次按键。(包括给的数字) 题解: 水题,暴力即可 code:

#include<bits/stdc++.h> //#pragma GCC optimize(2) #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为界限值,递减。 using namespace std; #define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0) #define ll long long #define ull unsigned long long #define ld long double #define PII pair<int,int> #define debug(a) cout <<#a << "=" << a << endl; const int INF = 0x3f3f3f3f; const ll LINF = 1ll<<60; const int mod=1e9+7; inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;} int main(){ int t; cin>>t; while(t--){ string x; cin>>x; string s; int ans=0; for(int j=1;j<=9;j++){ for(int i=1;i<=4;i++){ s+=j+'0'; ans+=s.size(); if(s==x) goto here; } s=""; } here: cout<<ans<<endl; } return 0; }
最新回复(0)