Analog and Enumeration

Analog and Enumeration

Simulation: As the name suggests, is what we simulate in code to achieve some kind of operation, how he said you how to do, he asks you to do what you do.

Simulation competition is the most basic of basic skills, the difficulty of thinking less demanding, mainly on the player's ability and code syntax

example:

1. Output all the "number daffodils."

The so-called "Narcissus number" refers to a three-digit number: the digits of its cube is equal to the number itself.

For example: 371 is a "Narcissus number" 371 + 3 = 3 ^ 7 ^ 3 ^ 3 + 1.

Solution: just enumerate all the three-digit calculate the cube and is equal to its own. The subject itself is not difficult, the code is no longer given.

  1. Looking three digits will be 1, 2, ..., 9 9 number into three groups, each consisting of three three-digit number, and configured so that the three three-digit 1: 2: 3 ratio, all the obtained satisfies the test three digits three conditions.

For example: three three digits 192, 384, 576 satisfying the above conditions

Solution: Just saw this question, my idea is to enumerate violence. But later found from 100-999 enumeration, then time will burst, so he can be simplified to enumerate only part of the 100-333 will double the number of times, and three times the number of comparisons to see if there is no overlapping figures, if not then established .

Code:

Wherein, Time [n] is used to calculate the number of the n-th digit being used, if used over a drunk driving, to finally judge the three-digit flag Flag is satisfied.

  1. Rehoboth formation

Rehoboth recently called in to play a Warcraft 3 games, this game can control the soldiers turned down opposite his home, and this game formation is very important, Rehoboth now arranged in a diamond-shaped, so please help Rehoboth row about the formation

[Sample input]

3 ^

[Sample output]

  ^

 ^^^

^^^^^

 ^^^

  ^

Solution: analog thought, in accordance with the subject of the claim n reverse loop line begins, to be noted that elements of the difference between every two lines where formation of two, only one line and the loop line, so that at the second output for less time ( Alternatively at least once, back up ring in the forward direction when the reverse)

Code:

 

4.usaco-1.1.2-Greedy Gift Givers

A total of n individuals to send gifts to each other, everyone got some money to the people they want to send a gift.

The same person the gifts are equivalent (integer), the extra money will leave their

Demand after n individual gifts while supplies last, and everyone earned or how much loss

Example:

 

Solution: To be honest I did not code for this question first glance = =

My idea is that when you enter the name into a numeric name, becoming the subscript of the array, and then turn to his gifts, in addition to the money he sent out, at the corresponding angle is added to standard, then leave their own section. (But it seems will burst ..?)

Code:

 

Guess you like

Origin www.cnblogs.com/SKTskyking/p/12283916.html