首页 > 其他分享 >1

1

时间:2024-07-07 10:33:05浏览次数:4  
标签: sy sx tx ty cin Delta

img

考虑到砖块的横着的线都是一条条形如 \(y=...\) 的线,不可避免,只有穿过竖着的线是可以节省。

观察发现,当 \(\Delta x\le \Delta y\) 时,通过斜着走可以规避掉竖线,答案为 \(\Delta y\)。

否则,出现一些无法规避的线,我们考虑令 \(s_x<t_x\)。

根据 \(x+y\) 奇偶性,分为两类起点,然后斜着走起点类型不变,接着稍微推一下。

一遍AC!

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sx,sy,tx,ty;
int main(){
    #ifndef ONLINE_JUDGE
    freopen("1.txt","r",stdin);
    #endif
    #ifdef ONLINE_JUDGE
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    #endif
    cin>>sx>>sy>>tx>>ty;
    if(sx>tx)swap(sx,tx),swap(sy,ty);
    bool type=(sx+sy)&1;
//    cout<<sx<<' '<<sy<<' '<<tx<<' '<<ty<<'\n';
    ll dx=abs(sx-tx),dy=abs(sy-ty);
    if(dx<=dy)cout<<dy;
    else{
    	ll d=dx-dy;
    	//type==1 1,3,5,7,9
    	//type==0 2,4,6,8,10
    	cout<<dy+(d+type>>1);
	}
    return 0;
}

标签:,sy,sx,tx,ty,cin,Delta
From: https://www.cnblogs.com/wscqwq/p/18288241

相关文章