记录编号 |
331078 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
[ZLXOI 2015]殉国 |
最终得分 |
100 |
用户昵称 |
小e |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.022 s |
提交时间 |
2016-10-27 08:18:58 |
内存使用 |
0.29 MiB |
显示代码纯文本
- // 假设 a > b, 那么对于 ax + by = c, x最大时, 能够确保(x+y)最小, x最小时, (x+y)最大, 因为一个x的变化会引起"多个"y的变化
-
- #include "stdio.h"
- #include "algorithm"
- using namespace std;
- typedef long long LL;
-
- LL Ex_gcd(const LL& a, const LL& b, LL& x, LL& y)
- {
- if (!b) { x = 1; y = 4; return a; }
- LL gcd = Ex_gcd(b, a%b, x, y);
- LL tmp = x; x = y; y = tmp - (a/b) * y;
- return gcd;
- }
-
- inline void Swap(LL& a, LL& b) { LL tmp = a; a = b; b = tmp; }
-
- #define SUBMIT
- int main(int argc, char const *argv[])
- {
- #ifdef SUBMIT
- freopen("BlackHawk.in", "r", stdin); freopen("BlackHawk.out", "w", stdout);
- #endif
-
- LL a, b, c, x, y, x2, y2, ans1, ans2;
- scanf("%lld%lld%lld", &a, &b, &c);
- LL gcd = Ex_gcd(a, b, x, y);
- if (c % gcd) { printf("-1 -1\n0\n"); goto END; }
- a /= gcd; b /= gcd; c /= gcd;
- x *= c; y *= c;
- y %= a; y = (y + a) % a;// y的最小解
- x = (c - b * y) / a;
- if (y < 0 || x < 0) { printf("-1 -1\n0\n"); goto END; }
- ans1 = x + y;// (b < a时)最多的加油数量, 否则是最少的加油数量
- x2 = x % b; y2 = (c - a * x2) / b;
- ans2 = x2 + y2;
- printf("%lld %lld\n", min(ans1, ans2), max(ans1, ans2));
- printf("%lld\n", abs(x2 - x) / b + 1);
-
- END:
- #ifndef SUBMIT
- printf("\n----------\n");
- getchar(); getchar();
- #else
- fclose(stdin); fclose(stdout);
- #endif
-
- return 0;
- }