USACO/Bronze
백준 5956 Symmetry (USACO January 2011 Bronze 1번)
ssam..
2020. 4. 8. 03:14
문제 링크: 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
|