CF 1465E Poman Numbers

https://codeforces.ml/contest/1465/problem/E

好题好题 做不来的都是好题[滑稽]

写的太好了555 羡慕这样的博客

https://www.cnblogs.com/dysyn1314/p/14183815.html

图片截取自上述链接

CF 1465E Poman Numbers

 CF 1465E Poman Numbers

 CF 1465E Poman Numbers

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 ll n, T;
 5 string s;
 6 ll cnt[30];
 7 int main(){
 8     cin >> n >> T;
 9     cin >> s;
10     
11     ll tmp = 0; 
12     tmp += (1ll << (s[n - 1] - 'a'));
13     tmp -= (1ll << (s[n - 2] - 'a'));
14     
15     for(int i = 0 ; i < n - 2 ; i++){
16         tmp -= (1ll << (s[i] - 'a'));
17     }
18     for(int i = 0 ; i < n - 2 ; i++){
19         cnt[s[i] - 'a']++;
20     }//最后两位不计入cnt 
21 
22     if(T < tmp){
23         cout << "NO" << endl;
24         return 0;
25     }else{
26         T -= tmp;
27     }
28     
29     for(int i = 25 ; i >= 0 ; i--){
30         ll p = (1ll << (i + 1));//多移一位,减法到加法 两倍 
31         ll k = min(cnt[i], T / p);
32         T -= k * p;
33     }
34     
35     if(!T){
36         cout << "YES" << endl;
37     }else{
38         cout << "NO" << endl;
39     }
40     
41     return 0;
42 }

 

上一篇:快速幂模板


下一篇:[Luogu] P3708 koishi的数学题