2.2.4 party lamps party lights

Source: Internet
Author: User

Http://acm.sdibt.edu.cn/JudgeOnline/problem.php? Id = 2328
Question: (such as question)
Input and Output: (such as the question)
Solution:
1. Because each button is pressed twice, the effect is the same. Therefore, each button is in the status of 2 ^ 4 = 16.
2. Because the electric lamp system has a personality and every six cycles, the status of the first six lights corresponding to the 16 states of the four buttons is enumerated. Then the analysis finds the rule:
-1 and 2 are equivalent to 3;
-2 and 3 are equivalent to 1;
-1 and 3 are equivalent to 2;
-Pressing 1 by 2 or 3 is equivalent to not pressing;
-The multiples of the difference 3 can also be converted to each other;
After removing the weight, we can get eight kinds of rules: Do not press, press 1, press 2, press 3, Press 4, press 1 to press 4, press 2 to press 4, and press 3 to press 4.
The minimum values are 0, 1, 1, 1, 2, and 2.
3. referring to a relatively evil method on the NOCOW-USACO-constant table method, save the status of the first six lights in the light array, then, a minnum array is used to store the number of times in the corresponding status. As follows:
int light[9][7]={    0,0,0,0,0,0,0,    0,0,0,0,0,0,0,//按1    0,0,0,1,1,1,0,//按1按4    0,0,1,0,1,0,1,//按3    0,0,1,1,0,1,1,//按1按4    0,1,0,0,1,0,0,//按4    0,1,0,1,0,1,0,//按2    0,1,1,0,0,0,1,//按2按4    0,1,1,1,1,1,1,//不按};//常量表 int minnum[9]={0,1,2,1,1,2,1,2,0};//对应常量表8个状态最少摁的次数
4. Then you can start writing code.
Core code:
flag1=false;    for(i=1;i<9;i++)    {        flag2=true;        for(j=1;j<=n;j++)        {            if(dat[j]==-1)//如果没有确定是亮或灭                continue;            tmp=j%6;//六位循环            if(tmp==0)//如果是6的倍数                tmp=6;            if(dat[j]!=light[i][tmp])//有个灯不同说明不是这个状态,结束判断            {                flag2=false;                break;            }        }        if(flag2==true&&c>=minnum[i])        {            flag1=true;//有一个满足条件就标记            for(j=1;j<=n;j++)            {                tmp=j%6;                if(tmp==0)                    tmp=6;                cout<<light[i][tmp];            }            cout<<endl;        }    }    if(flag1==false)        cout<<"IMPOSSIBLE"<<endl;


2.2.4 party lamps party lights

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.