QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639704#7781. Sheep Eat Wolvescy325TL 0ms3704kbC++202.8kb2024-10-13 21:43:522024-10-13 21:43:53

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 21:43:53]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3704kb
  • [2024-10-13 21:43:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
//struct an{
//    int sheep;
//    int wolf;
//    int edu;
//};
void solve(){
    int x,y,p,q;//
    cin>>x>>y>>p>>q;
    pair<int,int>an[2];//0 l 1 r
    an[0]={x,y};
    an[1]={0,0};
    bool fg=1;
    int idx=0;
    int cnt=0;
    int fg2=0;
    int transwolf,transsheep;
    while(an[1].first!=x){
        if (an[0].first <= p) {
            idx++;
            break;
        }
        if (idx % 2 == 0) {
            if (an[0].second > an[0].first + q && an[0].first != 0) {//狼吃羊
                transwolf = an[0].second - an[0].first - q;
                if (transwolf > p) { fg = 0; break;}//结束
                transsheep = p - transwolf;
                an[0].first -= transsheep;
                an[0].second -= transwolf;
                an[1].first += transsheep;
                an[1].second += transwolf;
                idx ++;
            } else if (an[0].second == an[0].first + q && an[0].first != 0) {//狼不吃羊
                transwolf = p / 2, transsheep = p / 2;
                an[0].first -= transsheep;
                an[0].second -= transwolf;
                an[1].first += transsheep;
                an[1].second += transwolf;
                idx++;
            } else {
                int cc = an[0].first + q - an[0].second ;
                transsheep=cc+(p - cc) / p;
                transwolf = (p - cc) / p;
                an[1].first += transsheep;
                if(transwolf>0)an[1].second += transwolf;
                an[0].first -= transsheep;
                if(transwolf>0)an[0].second -= transwolf;
                idx++;
            }
        }
//    右边 带狼走
        if (idx % 2 == 1) {
            if (an[0].first == 0) {
                idx++;
            }
            if (an[1].second > an[1].first + q && an[1].first != 0) {
                if(fg2==1&&q==0) { fg=0;break; }
                transwolf = an[1].second - an[1].first - q;
                if (transwolf > p) { fg = 0; break;}//结束
                an[1].second -= transwolf;
                an[0].second += transwolf;
                idx++;
                fg2=1;
            }else{
                idx++;
            }
        }
    }
    if(fg==0)cout<<"-1"<<endl;
    else cout<<idx<<endl;
}
signed main() {
    std::ios::sync_with_stdio(false);
//    // 获取起始时间
//    auto start = std::chrono::high_resolution_clock::now();
    int t;
//    cin>>t;
//    while(t--)solve();
    solve();
//    // 获取结束时间
//    auto end = std::chrono::high_resolution_clock::now();
//
//    // 计算运行时间,单位为毫秒
//    std::chrono::duration<double, std::milli> elapsed = end - start;
//
//    std::cout << "程序运行时间: " << elapsed.count() << " 毫秒" << std::endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Time Limit Exceeded

input:

3 3 1 1

output:


result: