Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 자료구조
- 백준
- 그리디 알고리즘
- XR Interaction Toolkit
- 투 포인터
- 정렬
- c++
- 재귀
- 유니온 파인드
- 다익스트라
- 알고리즘
- ue5
- BFS
- DFS
- 백트래킹
- 우선순위 큐
- Team Fortress 2
- 문자열
- 구현
- 스택
- 시뮬레이션
- 그래프
- 수학
- 트리
- VR
- 누적 합
- 유니티
- 브루트포스
- 다이나믹 프로그래밍
- Unreal Engine 5
Archives
- Today
- Total
1일1알
백준 16507번 어두운 건 무서워 C++ 본문
https://www.acmicpc.net/problem/16507
16507번: 어두운 건 무서워
첫 번째 줄에는 사진의 크기를 의미하는 정수 R, C (1 ≤ R, C ≤ 1,000)와 사진 일부분의 밝기 평균을 알아볼 개수를 의미하는 정수 Q (1 ≤ Q ≤ 10,000)가 주어진다. 다음 R개의 줄에 걸쳐 R×C 크기의 사
www.acmicpc.net
누적합
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int r, c, q;
vector<vector<int>> accSum;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> r >> c >> q;
accSum = vector<vector<int>>(r + 1, vector<int>(c + 1, 0));
for (int i = 1; i <= r; i++) {
int sum = 0;
for (int j = 1; j <= c; j++) {
int k;
cin >> k;
sum += k;
accSum[i][j] = sum;
}
}
for (int i = 0; i < q; i++) {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
int cnt = (r2 - r1 + 1) * (c2 - c1 + 1);
int sum = 0;
for (int j = r1; j <= r2; j++) {
sum += accSum[j][c2] - accSum[j][c1 - 1];
}
cout << sum / cnt << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 3184번 양 C++ (0) | 2023.06.30 |
---|---|
백준 3187번 양치기 꿍 C++ (0) | 2023.06.29 |
백준 1431번 시리얼 번호 C++ (0) | 2023.06.21 |
백준 12101번 1, 2, 3 더하기 2 C++ (0) | 2023.06.10 |
백준 17610번 양팔저울 C++ (0) | 2023.06.09 |