문제 링크: https://www.acmicpc.net/problem/5956
5956번: Symmetry
Farmer John loves symmetry and is currently arranging his cows on his field partitioned into an N x M (1 <= N <= 1,000,000,000; 1 <= M <= 1,000,000,000) grid. To preserve symmetry, Farmer John places cows in the following way. He puts a cow in the very cen
www.acmicpc.net
n과 m이 둘다 홀수임을 유지할때까지 계속 하나의 소 주위에 4마리 소를 더하는 과정을 반복하면 됨.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int ans = 0, r = 1;
while(n % 2 == 1 && m % 2 == 1) {
ans += r;
n /= 2;
m /= 2;
r *= 4;
}
cout << ans << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Bronze' 카테고리의 다른 글
백준 5958 Space Exploration (USACO January 2011 Bronze 3번) (0) | 2020.04.08 |
---|---|
백준 5957 Cleaning the Dishes (USACO January 2011 Bronze 2번) (0) | 2020.04.08 |
백준 5949 Adding Commas (USACO December 2010 Bronze 3번) (0) | 2020.04.06 |
백준 5948 Bad Random Numbers (USACO December 2010 Bronze 2번) (0) | 2020.04.06 |
백준 5947 Book Club (USACO December 2010 Bronze 1번) (0) | 2020.04.06 |