救救孩子

shao 发表于 4年前 · 关联问题 秧歌 Star 不要上补习班

#include <stdio.h> int mp[1100][1100] = {0}; int main(void) { int n, m, k; scanf("%d%d%d", &n, &m, &k); while (k--) { int x, y, v; scanf("%d%d%d", &x, &y, &v); mp[x][y] = v; } int q; scanf("%d", &q); while (q--) { int x1, x2, y1, y2; unsigned long long s = 0; scanf("%d%d%d%d", &x1, &x2, &y1, &y2); if (x1 > x2) x1 ^= x2 ^= x1; if (y1 > y2) y1 ^= y2 ^= y1; for (int i = x1; i <= x2; i++) for (int j = y1; j <= y2; j++) s += mp[i][j]; printf("%llu\n", s); } return 0; }

shao 发表于 4年前

fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuck 我再也不敢了,就这我debug了一年

if (x1 > x2) t = x1, x1 = x2, x2 = t; if (y1 > y2) t = y1, y1 = y2, y2 = t;

shao 发表于 4年前

#include <bits/stdc++.h> using namespace std; int mp[1100][1100] = {0}; int main(void) { int n, m, k; scanf("%d%d%d", &n, &m, &k); while (k--) { int x, y, v; scanf("%d%d%d", &x, &y, &v); mp[x][y] = v; } int q; scanf("%d", &q); while (q--) { int x1, x2, y1, y2; unsigned long long s = 0; scanf("%d%d%d%d", &x1, &x2, &y1, &y2); if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); for (int i = x1; i <= x2; i++) for (int j = y1; j <= y2; j++) s += mp[i][j]; printf("%llu\n", s); } return 0; }

bobby285271 发表于 4年前

这个解法其实不是正解(捂脸

估计是多测去掉之后就给水过去了...

shao 发表于 4年前

我会的也就这一点点了,记得有个啥算法,忘了。就是一边迭代一边做差那个,完全搞不懂