【AcWing-69】第 69 场周赛 题解
零、写在前面
这场比赛笔者认为相对并不难,稍加推理就可以取得很好的成绩(指
一、相遇问题
一道很简单的小学行程题目
(因为题目中保证
若
#include<bits/stdc++.h> using namespace std; inline long long read()//快速读入 { long long x=0; char ch=getchar(); while(ch>'9'||ch<'0') ch=getchar(); while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar(); return x; } signed main() { //freopen("meet.in","r",stdin); //freopen("meet.out","w",stdout); int T=read(); while(T--) { int x,y,a,b,ans; x=read(),y=read(),a=read(),b=read(); ans=(y-x)/(a+b);//计算答案 if(ans*(a+b)!=(y-x)) printf("-1\n");//不为整数就输出 -1 else printf("%d\n",ans)//不然输出刚刚计算的值 } return 0; }
二、击中战舰
我们由题目中发现,
所以也就是说,我们攻击占用的
所以我们每连续
然后记录完以后,我们就得出这些坐标总个数
题目要求我们只需要击中一艘就行,那我们考虑用 鸽巢原理,假设最坏情况前
#include<bits/stdc++.h> using namespace std; inline long long read() { long long x=0; char ch=getchar(); while(ch>'9'||ch<'0') ch=getchar(); while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar(); return x; } int n,sum,lon,cf; bool a[200009],t[200009]; vector<int>warship; signed main() { //freopen("fight.in","r",stdin); //freopen("fight.out","w",stdout); n=read(),sum=read(),lon=read(),cf=read(); int cnt=0; for(int i=1;i<=n;i++) { char c=getchar(); while(c=='\n') c=getchar(); a[i]=c-48; if((c-48)^1) cnt++;//若该位置为 0,即没被击中,连续个数就加 1 else cnt=0;//不然就清 0 if(!(cnt^lon)) cnt=0,warship.push_back(i);//存入数组 } printf("%u\n",warship.size()-sum+1); for(int i=0;i<warship.size()-sum+1;i++) printf("%d ",warship[i]);//随便输出 S-a+1 个坐标即可 return 0; }
三、解方程
这道题可以说是
我们发现,题目大意是给定一个 非负整数
分析:由题目可知,
我们把
不难发现
所以根据组合规律,答案就是
#include<bits/stdc++.h> using namespace std; inline long long read()//快速读入 { long long x=0; char ch=getchar(); while(ch>'9'||ch<'0') ch=getchar(); while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar(); return x; } inline long long count(int u)//统计 u 中 1 的个数 { int res=0,p=1; do res+=((u&p)>0),p<<=1; while(p<=u); return res; } signed main() { //freopen("equation.in","r",stdin); //freopen("equation.out","w",stdout); int T=read(); while(T--) printf("%lld\n",(1ll<<count(read())));//输出 return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】