fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 18540 (C++) Scored Nim
최초 업로드: 2025-09-05 02:33:41
최근 수정 시간: 2025-09-05 02:34:06
게시자: rlatjwls3333
카테고리: 백준
조회수: 4
# [Gold II] Scored Nim [문제 링크](https://www.acmicpc.net/problem/18540) ## 문제 설명 <p>Alice and Bob want to play Nim. Well, some kind of it.</p> <p>Initially, they have n heaps of stones, i-th heap containing a<sub>i</sub> stones. Players take alternating turns, Alice moves first. On their turn, a player chooses any heap with at least two stones and splits it into two new heaps with at least one stone in each. After that, the player colors all stones in one of the new heaps white and all stones in the other one black. The game lasts until every heap contains only one stone.</p> <p>After the game, Alice’s score is the number of white stones on the board, and Bob’s score is the number of black stones. Both players want to maximize their score and play optimally. What will be Alice’s score?</p> ## 입력 <p>The first line of input contains a single integer n (1 ≤ n ≤ 128).</p> <p>The second line of input contains n integers a<sub>1</sub>, a<sub>2</sub>, . . . , a<sub>n</sub> (2 ≤ a<sub>i</sub> ≤ 128).</p> <p>Note that the initial colors of the stones are irrelevant.</p> ## 출력 <p>Output a single integer: Alice’s score if both players play optimally.</p> ## 풀이 게임에서의 최선의 선택은 돌을 하나씩 가져가는 것입니다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int sum=0; while(n--) { int a; cin >> a; sum += a; } cout << (sum+1>>1); } ```