AtCoder Beginner Contest 334](https://atcoder.jp/contests/abc334) ABCDE
A - Christmas Present
签到不多说。
// AC one more times // nndbk #include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9 + 7; const int N = 2e5 + 10; int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int a,b; cin>>a>>b; cout<<(a>b?"Bat":"Glove")<<"\n"; return 0; }
B - Christmas Trees
题意:给你
思路:分类讨论,考虑
-
如果
在 之间( )。 (+1是因为k可以等于0) -
在区间 左边( )。前缀和思想,
-
在区间 右边边( )。
// AC one more times // nndbk #include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9 + 7; const int N = 2e5 + 10; int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); ll a,m,l,r; cin>>a>>m>>l>>r; ll res = 0; if(a < l) { res = (r-a)/m - ((l-1)-a)/m; } else if(l <= a && a <= r) { res = (r-a)/m + (a-l)/m + 1; } else if(a > r) { res = (a-l)/m - (a-(r+1))/m; } cout<<res<<"\n"; return 0; }
C - Socks 2
题意:高桥君有
现给你这
第一行输入
思路:思考怎么样差异度最小,肯定是排序之后相邻两个配对是最优的。
那么如果是偶数个之间两两配对即可。如果是奇数个呢?有一个是多出来的,那么是哪一个呢?不知道,我们考虑对前后缀都做一次前缀/后缀和,枚举是哪一个不要,答案取min就行了。
// AC one more times // nndbk #include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9 + 7; const int N = 5e5 + 10; int a[N],cnt; ll pre[N],suf[N],res; int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int n,k; cin>>n>>k; set<int>s; vector<int>v; for(int i = 1;i <= k; i++) { int x; cin>>x; s.insert(x); } for(int i = 1;i <= n; i++) { a[++cnt] = i; if(s.find(i) == s.end()) a[++cnt] = i; } int m = 2*n-k; // for(int i = 1;i <= m; i++) // cout<<a[i]<<" "; // cout<<"\n"; for(int i = 1;i <= m; i += 2) { pre[i] = pre[i-1] + abs(a[i]-a[i+1]); pre[i+1] = pre[i]; } for(int i = m;i >= 1; i -= 2) { suf[i] = suf[i+1] + abs(a[i]-a[i-1]); suf[i-1] = suf[i]; } if(m % 2 == 0){ res = pre[m]; }else{ res = 1e9; for(int i = 1;i <= m; i++) { res = min(res,pre[i-1]+suf[i+1]); } } cout<<res<<"\n"; return 0; }
D - Reindeer and Sleigh
题意:有
第一行输入
思路:排序+二分。
// AC one more times // nndbk #include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9 + 7; const int N = 2e5 + 10; ll need[N],s[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int n,q; cin>>n>>q; for(int i = 1;i <= n; i++) cin>>need[i]; sort(need+1,need+1+n); for(int i = 1;i <= n; i++) s[i] = s[i-1]+need[i]; for(int tc = 1;tc <= q; tc++) { ll x; cin>>x; ll l = 0, r = n; while(l<=r) { ll mid = (l+r)>>1; if(s[mid] <= x)l = mid+1; else r = mid-1; } cout<<l-1<<"\n"; } return 0; }
E - Christmas Color Grid 1
题意:给定 #
表示绿色,.
表示红色。
均匀随机一个红色块换成绿色,求绿色四连通块的期望数量,对
题意:先用
// AC one more times // nndbk #include <bits/stdc++.h> using namespace std; #define int long long typedef long long ll; const int mod = 998244353; const int N = 2e5 + 10; ll n,m,hav; int cnt = 1; char a[1010][1010]; int b[1010][1010]; int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}}; bool in(int x,int y) { return x >= 1 && x <= n && y >= 1 && y <= m; } void dfs(int x,int y,int num) { b[x][y] = num; for(int i = 0;i < 4; i++) { int tx = x + dir[i][0]; int ty = y + dir[i][1]; if(in(tx,ty) && a[tx][ty]=='#' && !b[tx][ty]) { dfs(tx,ty,num); } } } ll qmi(ll a, ll b, ll mod) { ll ans = 1 % mod; while(b) { if(b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin>>n>>m; for(int i = 1;i <= n; i++) for(int j = 1;j <= m; j++) cin>>a[i][j]; for(int i = 1;i <= n; i++) for(int j = 1;j <= m; j++)if(a[i][j]=='#' && !b[i][j]){ dfs(i,j,cnt); cnt++,hav++; } // for(int i = 1;i <= n; i++) // { // for(int j = 1;j <= m; j++) // { // cout<<a[i][j]; // } // cout<<"\n"; // } ll cnt = 0,ans = 0; for(int i = 1;i <= n; i++) { for(int j = 1;j <= m; j++) { if(a[i][j]=='.') { cnt++; set<ll>s; int d = 0; for(int k = 0;k < 4; k++) { int tx = i + dir[k][0]; int ty = j + dir[k][1]; if(in(tx,ty)&&a[tx][ty] != '.')s.insert(b[tx][ty]); if(in(tx,ty) && a[tx][ty]=='.')d++; } if(s.size() == 0 && d)ans++; // cout<<"s.size() = "<<s.size()<<"\n"; // for(auto x : s) // cout<<x<<" "; // cout<<"\n"; // cout<<"!!"<<hav-(s.size()-1)<<"\n"; ans += hav-max(0ll,(ll)s.size()-1); } } } ll g = __gcd(ans,cnt); // cout<<"hav = "<<hav<<"\n"; // cout<<"ans = "<<ans<<" cnt = "<<cnt<<"\n"; if(g) ans /= g,cnt /= g; int inv = qmi(cnt, mod - 2, mod)%mod; cout<<ans%mod*inv%mod<<"\n"; return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧