문제 링크: https://www.acmicpc.net/problem/14457
14457번: Cow Tipping
Farmer John occasionally has trouble with bored teenagers who visit his farm at night and tip over his cows. One morning, he wakes up to find it has happened again -- his N2 cows began the night grazing in a perfect N×N square grid arrangement (1 ≤ N ≤ 10)
www.acmicpc.net
오른쪽 아래 구석에서부터 1을 보면, farm의 제일 왼쪽 위 구석에서부터 1을 본 그 자리까지 모든 소를 뒤짚는걸 반복하면 됨.
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
29
30
31
32
33
34
35
36
37
|
#include <bits/stdc++.h>
using namespace std;
int N;
char farm[11][11];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for(int i = 0; i < N; i++) {
string s;
cin >> s;
for(int j = 0; j < s.size(); j++)
farm[i][j] = s[j];
}
int ans = 0;
for(int i = N - 1; i >= 0; i--) {
for(int j = N - 1; j >= 0; j--) {
if(farm[i][j] == '1') {
for(int k = 0; k <= i; k++) {
for(int l = 0; l <= j; l++) {
if(farm[k][l] == '0') farm[k][l] = '1';
else farm[k][l] = '0';
}
}
ans++;
}
}
}
cout << ans << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Bronze' 카테고리의 다른 글
백준 14468 소가 길을 건너간 이유 2 (USACO February 2017 Bronze 2번) (0) | 2020.02.29 |
---|---|
백준 14467 소가 길을 건너간 이유 1 (USACO February 2017 Bronze 1번) (0) | 2020.02.29 |
백준 14456 Hoof, Paper, Scissors (USACO January 2017 Bronze 2번) (0) | 2020.02.29 |
백준 14455 Don't Be Last! (USACO January 2017 Bronze 1번) (0) | 2020.02.28 |
백준 14175 The Cow-Signal (USACO December 2016 Bronze 3번) (0) | 2020.02.28 |