洛谷P1795无穷的序列
传送门:https://www.luogu.com.cn/problem/P1795
①:暴力暴力~
其实就是找到所有是1的位置,存起来,然后对照输出
但是感觉坑点蛮多的,C++输出换行用endl超时,得改成\n
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fi first
#define se second
const ll N=5005,mod=92084931,INF=1e18;
vector<ll>a;
void solve(){
ll n;
cin>>n;
ll num=1;
for(ll i=1;num<=1e9;i++){
a.push_back(num);
num+=i;
}
while(n--){
ll x;
cin>>x;
ll pos=lower_bound(a.begin(),a.end(),x)-a.begin();
if(a[pos]==x)cout<<1<<"\n";
else{
cout<<0<<"\n";
}
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll T = 1;
//cin >> T;
while (T--)
solve();
return 0;
}
②其实一上来想的是能不能通过打表找到1出现的位置规律,没错,还真能找到,涉及到数学方面的知识,明天再写这种方法,
🚧🚧🚧🚧🚧🚧🚧......
(占个位)

浙公网安备 33010602011771号