Usaco 2.24 party lamps

Source: Internet
Author: User

Initialization. All lights are on,

Then there are only four operations in total

1) All lights are reversed.

2) invert of the lamp numbered with an odd number

3) invert the number of lights with an even number

4) invert the light numbered 3 * x + 1

Now, ask, after performing Step C, some lights are on, some lights are off, and the possible combination of all the lights is obtained.

Question:

The effect of pressing a button twice is the same as that of a button without a button. Therefore, each button or press or do not press, a total of 2 ^ 4 = 16 states. Enumerate whether or not each button is pressed, generate the result, and sort the output (pay attention to the weight ).

/* ID: nanke691lang: C ++ task: lamps */# include <iostream> # include <fstream> # include <string> # include <algorithm> # include <set> using namespace STD; int N, C, T1, t2; int on [110] = {0}, off [110] = {0}; set <string> S; void judge (int A, int B, int C, int d) {string STR = ""; for (INT I = 1; I <= N; I ++) {int T = A; If (I-1) % 3 = 0) T + = D; if (I % 2 = 0) T + = C; else t + = B; If (T % 2 = 0) STR + = "1"; else STR + = "0";} For (INT I = 0; I <t1; I ++) {// cout <"on" <''<on [I] <<Endl; If (STR [ON [I]-1] = '0') return ;}for (INT I = 0; I <t2; I ++) {// cout <"off" <''<off [I] <Endl; If (STR [off [I]-1] = '1 ') return;} s. insert (STR);} int main () {freopen ("lamps. in "," r ", stdin); freopen (" lamps. out "," W ", stdout); int A; CIN> N> C; CIN> A; T1 = 0, T2 = 0; while (! =-1) {ON [T1 ++] = A; CIN> A;} CIN> A; while (! =-1) {off [T2 ++] = A; CIN> A ;}for (INT I = 0; I <2; I ++) for (Int J = 0; j <2; j ++) for (int K = 0; k <2; k ++) for (int l = 0; L <2; l ++) {int c = I + J + K + L; If (C % 2 = C % 2 & C <= C) judge (I, J, K, L);} set <string >:: iterator it = S. begin (); If (S. size ()! = 0) {for (; it! = S. End (); It ++) cout <* It <Endl;} else cout <"impossible" <Endl ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.