AC0个点,求大佬教教

P1588 [USACO07OPEN] Catch That Cow S

@[LoTLaneyyat](/user/910962) ``` #include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; queue<P> q; P p; int main(){ int t, a, b; cin >> t; while( t -- ){ cin >> a >> p.first; b = 1000000; q.push( P(p.first,0) ); while( q.size() ){ p = q.front(); q.pop(); if( p.first < a ){ p.second += a - p.first; if( b > p.second ) b = p.second; }else if( p.first % 2 == 0 ){ if( p.first / 2 > a )//是大于a!! q.push( P(p.first/2,p.second+1) ); else if( p.first - a > a - p.first/2 ) q.push( P(p.first/2,p.second+1) ); else{ p.second += p.first - a; if( b> p.second ) b = p.second; } }else{ q.push( P(p.first+1,p.second+1) ); q.push( P(p.first-1,p.second+1) ); } } cout << b << endl; } return 0; } ```
by yzyhaoshuai @ 2023-11-10 22:25:17


判断有问题,就自然出错了
by yzyhaoshuai @ 2023-11-10 22:27:13


**~~我是大佬~~**
by yzyhaoshuai @ 2023-11-12 14:49:18


|