比赛 |
防止浮躁的小练习v0.4 |
评测结果 |
AAAAAAAAAA |
题目名称 |
走出金字塔 |
最终得分 |
100 |
用户昵称 |
Fmuckss |
运行时间 |
0.011 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2016-10-13 18:54:40 |
显示代码纯文本
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- using namespace std;
- const int inf = 2e9;
-
- inline int cal(int dx, int dy) {
- int ans = 2;
- ans += (dx - 1) * 2;
- ans += max(0, dy - (dx - 1));
- return ans;
- }
-
- int n, m, k, s;
- int xa, xb;
-
- inline void solve() {
- scanf("%d %d %d %d", &n, &m, &k, &s);
- scanf("%d %d", &xa, &xb);
-
- int frx, fry, tox, toy, ans = inf, x, y;
- for (int i = 1; i <= m; i++) {
- scanf("%d %d", &x, &y);
- frx = xa, fry = xb, tox = x, toy = y;
- y = fry;
-
- if (frx > tox) {
- swap(frx, tox);
- swap(fry, toy);
- y = fry;
- }
-
- if (not (fry & 1)) {
- if (toy & 1) {
- toy++;
- if (toy <= tox * 2 - 1) {
- fry++;
- if (fry <= frx * 2 - 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 2);
- fry -= 2;
- if (fry >= 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 2);
- }
- fry = y;
- toy -= 2;
- if (toy >= 1) {
- fry++;
- if (fry <= frx * 2 - 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 2);
- fry -= 2;
- if (fry >= 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 2);
- }
- } else {
- fry++;
- if (fry <= frx * 2 - 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 1);
- fry -= 2;
- if (fry >= 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 1);
- }
- } else {
- if (toy & 1) {
- toy++;
- if(toy <= tox * 2 - 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 1);
- toy -= 2;
- if (toy >= 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 1);
- } else {
- ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))));
- }
- }
- }
-
- printf("%d\n", s - ((ans - 1) * k + 1) < 0 ? -1 : s - ((ans - 1) * k + 1));
- }
-
- int main() {
- freopen("ha14c.in", "r", stdin);
- freopen("ha14c.out", "w", stdout);
- solve();
- return 0;
- }