Codeforces Round #513 by Barcelona bootcamp (rated, div. 1 + div. 2)
- Solved:2 out of 8 ...
- rank:2730 Unrated
- A. Phone Numbers
- Difficulty: Universal group.
- Simulation can be:
- Summary: Do not waste too much time on simple questions, to improve the accuracy of the problem.
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;const int N = 100 + 10;int cnt =0;int main(){ int n; scanf("%d", &n); for(int i=1;i<=n;i++) { char ch; cin>>ch; if(ch == ‘8‘) cnt++; } int ans=0; while(n){ if(cnt&&n>=11) cnt--,n-=11,ans++; else break; } printf("%d",ans); return 0;}
- B. Maximum Sum of Digits
- Difficulty: Increase group D1T1?
- greedy
- for numbers less than 10, a = N, b = 0
- for numbers greater than 10, we choose to use as many ⑨ as possible to gather a until a is greater than N, and then the highest bit of a is the highest bit of N-1, which constructs a. 。
- and then B = n-a.
- Tips:
- pow () function or something ... or write yourself a long long fast power bar ...
- Sample Touching ... Fortunately played a watch to find the law ...
- Summary:
- conclusion or greedy problem must be a table to write to check the correctness of the conclusion.
- to prevent intermediate bursts of long long, in the problem of big data, you can open long long as far as possible.
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath>using namespace Std;long long cal (Long long a) {long long ans=0; while (a) {long long dig=a%10; Ans+=dig; a/=10; } return ans; Long Long Fpow (long long A,long long B) {long long ans=1; for (; b;b>>=1) {if (b&1) ans*=a; A*=a; } return ans; int main () {long long n; scanf ("%i64d", &n); Long long ans; Long Long A; if (n<10) a= N; else {a = 0;long long cnt=0; while (a<=n) a=a*10+9,cnt++; if (a>n) a/=10,cnt--; Long long Top;long long x=n; while (x) {if (x/10>0) TOP=X/10; x/=10; } top--; Long Long Pw=fpow (10,cnt); A= (long Long) top*pw+a; } long long B; if (n<10) b=0; else {b = n-a; } ans = cal (a) + cal (b); printf ("%i64d", ans); return 0;}
Codeforces Round #513 by Barcelona bootcamp (rated, div. 1 + div. 2)