比赛 防止浮躁的小练习v0.4 评测结果 AAAAAAAAAA
题目名称 走出金字塔 最终得分 100
用户昵称 Fmuckss 运行时间 0.011 s
代码语言 C++ 内存使用 0.31 MiB
提交时间 2016-10-13 18:54:40
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. using namespace std;
  5. const int inf = 2e9;
  6.  
  7. inline int cal(int dx, int dy) {
  8. int ans = 2;
  9. ans += (dx - 1) * 2;
  10. ans += max(0, dy - (dx - 1));
  11. return ans;
  12. }
  13.  
  14. int n, m, k, s;
  15. int xa, xb;
  16.  
  17. inline void solve() {
  18. scanf("%d %d %d %d", &n, &m, &k, &s);
  19. scanf("%d %d", &xa, &xb);
  20. int frx, fry, tox, toy, ans = inf, x, y;
  21. for (int i = 1; i <= m; i++) {
  22. scanf("%d %d", &x, &y);
  23. frx = xa, fry = xb, tox = x, toy = y;
  24. y = fry;
  25. if (frx > tox) {
  26. swap(frx, tox);
  27. swap(fry, toy);
  28. y = fry;
  29. }
  30. if (not (fry & 1)) {
  31. if (toy & 1) {
  32. toy++;
  33. if (toy <= tox * 2 - 1) {
  34. fry++;
  35. if (fry <= frx * 2 - 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 2);
  36. fry -= 2;
  37. if (fry >= 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 2);
  38. }
  39. fry = y;
  40. toy -= 2;
  41. if (toy >= 1) {
  42. fry++;
  43. if (fry <= frx * 2 - 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 2);
  44. fry -= 2;
  45. if (fry >= 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 2);
  46. }
  47. } else {
  48. fry++;
  49. if (fry <= frx * 2 - 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 1);
  50. fry -= 2;
  51. if (fry >= 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 1);
  52. }
  53. } else {
  54. if (toy & 1) {
  55. toy++;
  56. if(toy <= tox * 2 - 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 1);
  57. toy -= 2;
  58. if (toy >= 1) ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))) + 1);
  59. } else {
  60. ans = min(ans, cal(tox - frx, abs((toy - tox) - (fry - frx))));
  61. }
  62. }
  63. }
  64. printf("%d\n", s - ((ans - 1) * k + 1) < 0 ? -1 : s - ((ans - 1) * k + 1));
  65. }
  66.  
  67. int main() {
  68. freopen("ha14c.in", "r", stdin);
  69. freopen("ha14c.out", "w", stdout);
  70. solve();
  71. return 0;
  72. }