Confusing coin flip (P1146 Los problem solution to a problem Valley, Java language description)

Questions asked

P1146 topic Link

Here Insert Picture Description

analysis

This question is really doing it to confuse human behavior ......

This is another topic that Italy's administrator dalao are Tucao too, simply, but later changed it seems to change expression ......

Let's look at this question:

N-1 flip coins, each time there is not a coin flip, flipping is the i-th flip all the coins except the i-th coin.
So long as the n coins turn upside down on it, the number of which is n times.

Here is proof of a dalao write, it is worth learning:
Here Insert Picture Description
Here Insert Picture Description

Really tql, tql, tql ...
Here Insert Picture Description

To footer mortal difficult to prove I ah (may be since I know the results would not bother to think how evidence hhh who knows)

AC Code (Java description language)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        scanner.close();
        int[] coins = new int[num];
        System.out.println(num);
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < num; j++) {
                if (i != j){
                    coins[j] ^= 1;
                }
            }
            StringBuilder builder = new StringBuilder();
            for (int j = 0; j < num; j++) {
                builder.append(coins[j]);
            }
            System.out.println(builder);
        }
    }
}
Published 402 original articles · won praise 659 · views 60000 +

Guess you like

Origin blog.csdn.net/weixin_43896318/article/details/104103512