QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#761012 | #7781. Sheep Eat Wolves | jiejiejiang | WA | 0ms | 3608kb | C++20 | 2.1kb | 2024-11-18 20:35:38 | 2024-11-18 20:35:39 |
Judging History
answer
// #pragma GCC optimize(2)
/* // 快读:返回读入的第一个整数
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <cfloat>
#include <set>
#include <climits>
using namespace std;
using f64 = long double;
// #define int long long
// # define int unsigned long long
// #define endl '\n'
// #define minn(a,b) (a>b?b:a)
const int N = 1e5 + 10, M = N * N;
const int base = 1e9;
const int basebit = 9;
const int mod = 1e9 + 7;
const long long INF = 1e18;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PIII;
typedef pair<f64, int> PDI;
int x, y, a, b;
void solve()
{
// 有个问题,,船一定要装满吗?
cin >> x >> y >> a >> b;
// 直接模拟
int xx = 0, yy = 0;
int tim = 0, size = 0; // size为0时代表在本岸,为1时在对岸
while (1) // 如果此时在本岸且羊的数量可以一条船带走,结束模拟
{
if (!size)
{
int tem1 = max(0, y - (x + b + 1)); // 必须带走的狼群数量
if (tem1 > a)
{
cout << "-1" << endl;
return;
}
int tem = (a - tem1) / 2;
y -= tem1 + tem;
yy += tem1 + tem;
x -= tem;
xx += tem;
}
else
{
int tem1 = max(0, y - (x + b + 1)); // 必须带走的狼群数量
if (tem1 > a)
{
cout << "-1" << endl;
return;
}
yy -= tem1;
y += tem1;
}
tim++, size ^= 1;
if (x <= a && size == 0)
break;
if (tim >= 1000)
{
cout << "-1" << endl;
return;
}
}
tim++;
cout << tim << endl;
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3588kb
input:
1 1 1 0
output:
3
result:
wrong answer 1st numbers differ - expected: '1', found: '3'