본문 바로가기

USACO/Bronze

백준 14457 Cow Tipping (USACO January 2017 Bronze 3번)

문제 링크: 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