QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639743 | #7781. Sheep Eat Wolves | cy325 | WA | 0ms | 3704kb | C++20 | 3.7kb | 2024-10-13 22:06:09 | 2024-10-13 22:06:09 |
Judging History
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;
if(transwolf==0&&transsheep==0){
if(an[1].first<an[1].second){
transwolf=0;
transsheep=1;
}else{
transwolf=1;
transsheep=0;
}
}
an[0].first -= transsheep;
an[0].second -= transwolf;
an[1].first += transsheep;
an[1].second += transwolf;
idx++;
} else if(an[0].first+q>an[0].second){
int cc=an[0].first+q-an[0].second;
transwolf=cc/2;
transsheep=cc/2+cc;
an[1].first += transsheep;
if(transwolf>0)an[1].second += transwolf;
an[0].first -= transsheep;
if(transwolf>0)an[0].second -= transwolf;
idx++;
}else{
int cc = an[0].first + q - an[0].second ;
if(q==1){
transsheep = cc + (p - cc) / 2;
transwolf = (p - cc) / 2;
}else{
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: 3576kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
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: 0
Accepted
time: 0ms
memory: 3524kb
input:
3 3 1 1
output:
7
result:
ok 1 number(s): "7"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
3 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3656kb
input:
10 9 1 10
output:
3
result:
wrong answer 1st numbers differ - expected: '19', found: '3'