Poj 3210 Coins(推理)

来源:互联网 发布:freenom域名怎么用 编辑:程序博客网 时间:2024/06/09 18:59

题目:http://poj.org/problem?id=3210

Coins
Time Limit: 1000MS Memory Limit: 131072KTotal Submissions: 7012 Accepted: 4624

Description

Snoopy has three coins. One day he tossed them on a table then and tried to flip some of them so that they had either all heads or all tails facing up. After several attempts, he found that regardless of the initial configuration of the coins, he could always achieve the goal by doing exactly two flippings, under the condition that only one coin could be flipped each time and a coin could be flipped more than once. He also noticed that he could never succeed with less than two flippings.

Snoopy then wondered, if he had n coins, was there a minimum number x such that he could do exactly x flippings to satisfy his requirements?

Input

The input contains multiple test cases. Each test case consists of a single positive integern (n < 10,000) on a separate line. A zero indicates the end of input and should not be processed.

Output

For each test case output a single line containing your answer without leading or trailing spaces. If the answer does not exist, output “No Solution!

Sample Input

230

Sample Output

No Solution!2

/*如果硬币的数目是偶数,那么初始不同面的硬币数a,b有两种情况:1.a是偶数,b是偶数,那么最小的翻转数就是偶数.2.a是奇数,b是奇数,那么最小的翻转数就是奇数.所以最小的翻转数十不存在的(不确定的)如果硬币的数目是奇数,那么初始不同面的硬币数a,b的情况:a是偶数,b是奇数(反之一样),要让硬币满足要求:全部面朝上或朝下(下和上都能做到)那么极限情况下最小的异面数就是一个。所以要满足"(下和上都能做到)"的翻转数就是n-1.*/#include <iostream>#include <cstdio>using namespace std;int main(){    int n;    while(cin>>n&&n){        if(n&1) printf("%d\n",n-1);        else puts("No Solution!");    }    return 0;}



0 0