2 条题解
-
0曾经的我 (zengzhiyuan) LV 9 @ 2024-8-8 19:40:26
刚开始我想着用BFS做的......
#include<bits/stdc++.h> using namespace std; #define ll long long #define abs_(x) max(x,-(x)) ll s,t,l,r; int get(ll nl,ll nr) { if(nl<=t&&nr>=t) return 0; ll tl=min(min(2*l-nl,2*l-nr),min(2*r-nl,2*r-nr)); ll tr=max(max(2*l-nl,2*l-nr),max(2*r-nl,2*r-nr)); return get(tl,tr)+1; } int work() { scanf("%lld %lld %lld %lld",&s,&t,&l,&r); if(s%2!=t%2) return -1; if(l==r) { if(abs_(s-l)!=abs_(t-l)) return -1; if(s==t) return 0; return 1; } return get(s,s); } signed main() { int T; scanf("%d",&T); while(T--) printf("%d\n",work()); return 0; }
-
02024-8-8 18:14:38@
#include<bits/stdc++.h> using namespace std; #define ll long long #define abs_(x) max(x,-(x)) ll s,t,l,r; int get(ll nl,ll nr) { if(nl<=t&&nr>=t) return 0; ll tl=min(min(2*l-nl,2*l-nr),min(2*r-nl,2*r-nr)); ll tr=max(max(2*l-nl,2*l-nr),max(2*r-nl,2*r-nr)); return get(tl,tr)+1; } int work() { scanf("%lld %lld %lld %lld",&s,&t,&l,&r); if(s%2!=t%2) return -1; if(l==r) { if(abs_(s-l)!=abs_(t-l)) return -1; if(s==t) return 0; return 1; } return get(s,s); } signed main() { int T; scanf("%d",&T); while(T--) printf("%d\n",work()); return 0; }
- 1
信息
- ID
- 2999
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 95
- 已通过
- 14
- 上传者