Unknown Switches Simulation

Source: Internet
Author: User

                        Unknown Switches

Abstract: Each switch may control a plurality of lights, each lamp can only be controlled by a switch, give the operation of the Q switch Change, and the change of the lamp. Ask each lamp to be controlled by that switch.

Analysis: Using FLAG[MS] to indicate the switching condition of switch I, link[ms][40] indicates the control relationship between the light I and the switch J.

Simulation, for each operation of the switch I and light j, if they are in the same state, then they may exist control relationship, if the state is different, then there must be no control relationship.

Finally count each lamp by how many switch control, if is 1, then can determine by which switch control, otherwise, insufficient information, cannot determine control relation, input '? ’。

1 /********************************2 Please don ' t hack me!!/(ToT)/~~3                 __------__4               /~          ~5              | //^\\//^\|6            /~~\  || t| | t|:~7 | |6 | | ___|_|_||:|8            \__. /o \ '9             | (O)Ten    /~~~~\    `\  \         / One   | |~~\ | )  ~------~` A /' |   | | /     ____ /~~~) - (_/' | | |    /' | ( | -        | | | \    /   __)/  the \ \ \ \ /' \ ' -          \  \|\        /   | |\___| -            \ | \____/     | | - /^~> \ _/< +           |         | \        -           | | \        \         +           -^-\  \       | ) A                `\_______/^\______/ at ************************************/ -  -#include <iostream> -#include <cstdio> -#include <cstring> -#include <cmath> in#include <algorithm> -#include <string> to#include <vector> +#include <Set> -#include <map> the#include <queue> *#include <stack> $#include <cstdlib>Panax Notoginseng#include <sstream> - using namespacestd; thetypedefLong LongLL; + ConstLL INF =0x5fffffff; A Const DoubleEXP =0x5fffffff; the Constll MOD = (ll) 1e9+7; + Const intMS =1005; -  $ intlink[ms][ +];//whether there is a control relationship between the lamp I and the Switch J. 1 means there is, 2 means there must be no $ BOOLFLAG[MS];//the status of the lamp I.  - CharS[ms]; - CharB[ms]; the intn,m,q; - Wuyi intMain () { the      while(SCANF ("%d%d%d", &n,&m,&q) = =3&& (n + M +q)) { -memset (Link,0,sizeof(link)); Wumemset (Flag,0,sizeof(flag)); -         if(!q) { About             if(n = =1) { $                  for(inti =0; I < m;i++) -printf"0"); -printf"\ n"); -             } A             Else { +                  for(inti =0; I < m; i++) { theprintf"?"); -                 } $printf"\ n"); the             } the             Continue; the         } the          while(q--) { -scanf"%s%s", s,b); in              for(inti =0; I < n; i++) { the                 if(S[i] = ='1'){ the                     if(Flag[i]) AboutFlag[i] =0; the                     Else theFlag[i] =1; the                 } +             } -              for(inti =0; I < n; i++){ the                  for(intj =0; J < m;j++) {Bayi                     if(Flag[i] && b[j] = ='1'&& Link[j][i]! =2) theLink[j][i] =1; the                     Else if(Flag[i] = =0&& B[j] = ='0'&& Link[j][i]! =2) -Link[j][i] =1; -                     Else theLink[j][i] =2;//there must be no control relationship.  the                 } the             } the         } -          for(inti =0; I < m; i++) { the             intCNT =0; the             intindex =0; the              for(intj =0; J < N; J + +) {94                 if(Link[i][j] = =1) { thecnt++; theindex =J; the                 }98             } About             if(CNT = =1) { -                 if(Index <Ten)101printf"%d", index);102                 Else103printf"%c", index-Ten+'A');104             } the             Else106printf"?");107         }108printf"\ n");109     } the     return 0;111}

Unknown Switches Simulation

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.