START195——Bugged Robot 有缺陷的机器人(遇到坐标图不要慌,把x和y拆开来) · znzryb
## 思路讲解
不难发现,这个x坐标完全取决于奇数操作,y坐标完全取决于偶数操作。
在y有y个操作下,其可以产生 $[y+1,2^{y}]$ 种子集和(就是这个范围内的都能生成)。
```cpp
FOR(i,1,N){
if(i*i>N) break;
if(N%i==0){
ll di=N/i;
FOR(j,1,N){
ll y=j/2,x=(j+1)/2;
if(binpow(2,y)>N) break;
if(i>=x && i<=binpow(2,x-1) && di<=binpow(2,y) && di>=y+1){
ans=min(ans,j);
}
if(di>=x && di<=binpow(2,x-1) && i<=binpow(2,y) && i>=y+1){
ans=min(ans,j);
}
}
}
}
```
## AC代码
::: 源代码
```cpp
// Problem: Bugged Robot 有缺陷的机器人
// Contest: CodeChef - START195
// URL: https://www.codechef.com/problems/DIRFOLLOW?tab=statement
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// by Gospel_rock
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define pb push_back
#define EB emplace_back
#define EM emplace
#define FI first
#define SE second
#define SZ(a) ((int) a.size())
#define FOR(i, a, b) for (long long i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (long long i = (a); i >= (b); --i)
#define debug(var) cerr << #var <<":"<<var<<"\n";
#define lson(var) (var<<1)
#define rson(var) ((var<<1)+1)
using namespace std;
using ll = long long;using ull = unsigned long long;
using DB=double;using LD=long double;
// using i128 = __int128;
using pdd = pair<DB,DB>;using plb = pair<ll,bool>;
using pll = pair<ll,ll>;using vll=vector<ll>;using vb=vector<bool>;
using tll = tuple<ll,ll,ll>;
using vpll = vector<pll>;
using arr3 = array<ll,3> ;using arr2 = array<ll,2>;
constexpr ll MAXN=(ll)1e6+10,INF=(ll)1e17+9; // 1e18+9也是素数
constexpr ll mod=(ll)1e9+7; // 998244353
constexpr double eps=1e-8;const double pi=acos(-1.0);
ll N,M,Q,X,K,T,lT,A[MAXN];
/*
题意简单来讲就是告诉你N,然后问你最终可能到达位置为N的操作序列长度最少为几?
如果没有,输出-1。
*/
ll binpow(ll a,ll k){ // 迭代快速幂
ll res=1;
while(k>0){
if((k&1)==1) res=a*res;
a=a*a;
k>>=1;
}
return res;
}
inline void __(){
cin>>N;
ll ans=INF;
FOR(i,1,N){
if(i*i>N) break;
if(N%i==0){
ll di=N/i;
FOR(j,1,N){
ll y=j/2,x=(j+1)/2;
if(binpow(2,y)>N) break;
// if(j==1) l=1,r=1;
#ifdef LOCAL
debug(j);debug(x);debug(y);
#endif
if(i>=x && i<=binpow(2,x-1) && di<=binpow(2,y) && di>=y+1){
ans=min(ans,j);
}
if(di>=x && di<=binpow(2,x-1) && i<=binpow(2,y) && i>=y+1){
ans=min(ans,j);
}
}
}
}
cout<<(ans==INF?-1:ans)<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>lT;
while(lT--)
__();
return 0;
}
/*
1
36
ans :
7
AC https://www.codechef.com/viewsolution/1174368960
*/
```
:::
## 心路历程(WA,TLE,MLE……)