无printf和scanf
2026-07-22 20:43:14
发布于:浙江
17阅读
0回复
0点赞
29-5-1行无printf和scanf!
------珍爱生命,远离抄袭------
这题不大需要printf和scanf,a数组直接开1e6+10+const int 简单好写。
问我为什么是29-5-1?
答:总29行-5行注释-1行#include <algorithm>
算下来是23行纯代码。
这题非常简单,用cin即可,亲测不会TLE,用我的写法是2ms通关
如果想完作业直接暴搜就行
这道题靠的是二分查找,但实际不用写二分,用lower_bound就行。

这道题过了可以去洛谷改几行谁双倍经验哦!
喵~直接上代码
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
const int mx=1e6+10;
int a[mx]={};
int main (){
/* ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
//或
ios::sync_with_stdio(false);
cin.tie(0);*/
int n,t;
cin>>n>>t;
for(int i=1;i<=n;i++){
cin>>a[i];
}
while(t--){
int x;
cin>>x;
int ans=lower_bound(a+1,a+n+1,x)-a;
if(a[ans]==x){
cout<<ans<<' ';
}
else{
cout<<-1<<' ';
}
}
return 0;
}
注:注释的两行上面一个长一点,下面一个豆老师爱用喵
全部评论 3
顶顶顶
2026-07-22 来自 浙江
0大大大
2026-07-22 来自 浙江
0顶顶顶
2026-07-22 来自 浙江
0







有帮助,赞一个