OJ 比赛列表有蓝桥杯、CCF-CSP、天梯赛官方练习系统 / 题目集入口,有需要测试比赛评测环境的可以前往。

救救孩子

王家晔(HK-SHAO) 发表于 5个月前 · 关联问题 秧歌 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; }

王家晔(HK-SHAO) 发表于 5个月前

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

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

王家晔(HK-SHAO) 发表于 5个月前

#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; }

Bobby Rong 发表于 5个月前

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

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

王家晔(HK-SHAO) 发表于 5个月前

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