AtCoder Beginner Contest 301

1|0A - Overall Winner


#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios::sync_with_stdio(false); cin.tie(nullptr) , cout.tie(nullptr); int n; cin >> n; string s; cin >> s; int t = 0 , a = 0; for( auto i : s ) if( i == 'T' ) t ++; else a ++; if( t > a ) cout << "T"; else if( t < a )cout << "A"; else { if( s.back() == 'T' ) cout << "A"; else cout << "T"; } return 0; }

2|0B - Fill the Gaps


#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios::sync_with_stdio(false); cin.tie(nullptr) , cout.tie(nullptr); int n; cin >> n; vector<int> a(n); for( int i = 0 ; i < n ; i ++ ) cin >> a[i]; vector<int> b; b.push_back( a[0] ); for( int i = 1 ; i < n ; i ++ ){ if( a[i] > b.back() ){ for( int j = b.back()+1 ; j < a[i] ; j ++ ) b.push_back(j); }else { for( int j = b.back()-1 ; j > a[i] ; j -- ) b.push_back(j); } b.push_back( a[i] ); } for( auto i : b ) cout << i << " "; return 0; }

3|0C - AtCoder Cards


#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios::sync_with_stdio(false); cin.tie(nullptr) , cout.tie(nullptr); string a , b ; cin >> a >> b; map<char , int > cnt , ans ; int d = 0; for( auto i : a ) cnt[i] ++; for( auto i : b ) ans[i] ++; for( auto i : "atcoder" ){ if( cnt[i] == ans[i] ) continue; else if( cnt[i] > ans[i] ) ans['@'] -= cnt[i] - ans[i] , ans[i] = cnt[i]; else cnt['@'] -= ans[i] - cnt[i] , cnt[i] = ans[i]; } if( cnt['@'] < 0 || ans['@'] < 0 || cnt['@'] != ans['@'] ){ cout << "No\n"; return 0; } set<char> st; st.insert('a'); st.insert('t'); st.insert('c'); st.insert('o'); st.insert('d'); st.insert('e'); st.insert('r'); for( auto [ k , v ] : cnt ){ if( st.count(k) ) continue; if( v != ans[k] ){ cout << "No\n"; return 0; } } for( auto [ k , v ] : ans ){ if( st.count(k) ) continue; if( v != cnt[k] ){ cout << "No\n"; return 0; } } cout << "Yes\n"; return 0; }

4|0D - Bitmask


?当成是一个二进制数,去二分这个数的大小,判断的时候把二进制数还原会原数就可以比较大小了。

#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios::sync_with_stdio(false); cin.tie(nullptr) , cout.tie(nullptr); string s; int n , m = 0; cin >> s >> n; vector<int> a((int)s.size()); for( int i = 0 ; i < (int)s.size() ; i ++ ){ if( s[i] == '?' ) a[i] = -1, m ++; else if( s[i] == '1' ) a[i] = 1; else a[i] = 0; } auto op = [a]( int x ){ auto b = a; for( int i = b.size()-1 ; i >= 0 ; i -- ) if( b[i] == -1 ) b[i] = x % 2 , x /= 2; int ans = 0; for( int i : b ) ans = ans * 2ll + i; return ans; }; int l = 0 , r = (1ll<<m) - 1 , res = -1; while( l <= r ){ int mid = ( l + r ) >> 1; int d = op(mid); if( d <= n ) res = d , l = mid + 1; else r = mid - 1; } cout << res << "\n"; return 0; }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/17420758.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· Apache Tomcat RCE漏洞复现(CVE-2025-24813)
历史上的今天:
2022-05-22 NumPy 入门
点击右上角即可分享
微信分享提示