就是模拟。同一个开关按2下相当于没按,那么,如果一共按0下,就是没按,按1下就是4个开关的1个,按2下可能相当于实际按了0下或按2下,按3下实际按了1下或3下,之后如果是奇数,相当于按1或3下,偶数相当于按0,2,4下。再看一下是否符合。数据太小根本不会超时。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF; int getdgt(int x)
{
int res=;
for(;x;)
{
if(x&)++res;
x/=;
}
return res;
} void func(int x,bitset<> &y)
{
if(x&)y.flip();
if(x&)
{
for(int i=;i<=;i+=)y[i]=!y[i];
}
if(x&)
{
for(int i=;i<=;i+=)y[i]=!y[i];
}
if(x&)
{
for(int i=;i<=;i+=)y[i]=!y[i];
}
} bool chk(bitset<> bt,vector<int> &x,int sta)
{
for(int i=;i<x.size();++i)
{
if(bt[x[i]]!=sta)return ;
}
return ;
} void work(int n,set<int> time,vector<int> lg,vector<int> dk)
{
bool ok=;
vector<string> vct;
for(int i=;i<(<<);++i)
{
if(time.find(getdgt(i))!=time.end())
{
bitset<> bt;
bt.set();
func(i,bt);
if(chk(bt,lg,)&&chk(bt,dk,))
{
ok=;
string tmp="";
for(int j=;j<=n;++j)
{
tmp+=bt[j]+'';
}
vct.push_back(tmp);
}
}
}
sort(vct.begin(),vct.end());
if(ok==)cout<<"IMPOSSIBLE"<<endl;
else
{
for(int i=;i<vct.size();++i)
{
cout<<vct[i]<<endl;
}
}
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//for(lon time=1;time<=casenum;++time)
{
int n,cnt;
cin>>n>>cnt;
vector<int> lg,dk;
for(;;)
{
int tmp;
cin>>tmp;
if(tmp==-)break;
else lg.push_back(tmp);
}
for(;;)
{
int tmp;
cin>>tmp;
if(tmp==-)break;
else dk.push_back(tmp);
}
//sort(lg.begin(),lg.end());
//sort(dk.begin(),dk.end());
set<int> st;
if(cnt==)
{
st.insert();
work(n,st,lg,dk);
}
else if(cnt==)
{
st.insert();
work(n,st,lg,dk);
}
else if(cnt==)
{
st.insert();
st.insert();
work(n,st,lg,dk);
}
else if(cnt&)
{
st.insert();
st.insert();
work(n,st,lg,dk);
}
else
{
st.insert();
st.insert();
st.insert();
work(n,st,lg,dk);
}
}
return ;
}

p1468 Party Lamps的更多相关文章

  1. 【搜索】P1468 派对灯 Party Lamps

    P1468 派对灯 Party Lamps 我们来分析一下对灯的操作 1.对所有灯的,这时吧所有灯看成一个整体 2.奇偶数的操作,这时可以把每两个数看成一个循环节 3.对3X+ 1的操作,这时可以把每 ...

  2. luogu P1468 派对灯 Party Lamps

    题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄 ...

  3. P1468 派对灯 Party Lamps(BIG 模拟)

    题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄 ...

  4. luoguP1468 派对灯 Party Lamps x

    P1468 派对灯 Party Lamps 题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当 ...

  5. 【USACO 2.2】Party Lamps

    四种开关,n盏灯,1:改变所有灯状态,2:改变奇数灯状态,3:改变偶数灯状态,4:改变3k+1灯状态 给你按开关的总次数c和部分灯限制条件(开或关),一开始都是开着的.($c \leq 10000,n ...

  6. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  7. poj 1176 Party Lamps

    http://poj.org/problem?id=1176 Party Lamps Time Limit: 1000MS   Memory Limit: 10000K Total Submissio ...

  8. USACO Section 2.2: Party Lamps

    这题有个小技巧, 按一个键两次等于没按,所以如果depsum > 16的话其实不用做深搜到depsum次,而只要16次就可以了. /* ID: yingzho1 LANG: C++ TASK: ...

  9. UVA 12382 Grid of Lamps 贪心

    题目链接: C - Grid of Lamps Time Limit:1000MSMemory Limit: 0KB 问题描述 We have a grid of lamps. Some of the ...

随机推荐

  1. 探究is与==的区别

    1.is  和 ==的区别: 主要参考内存地址: 部分字符串和数字有固定的小数据池: 比如: a="abc" a1="abc" print(id(a),id(a ...

  2. 数论+矩阵快速幂|斐波那契|2014年蓝桥杯A组9-fishers

    标题:斐波那契 斐波那契数列大家都非常熟悉.它的定义是: f(x) = 1 .... (x=1,2) f(x) = f(x-1) + f(x-2) .... (x>2) 对于给定的整数 n 和 ...

  3. 【拼接属性查询方式】MySql某一列属性值为拼接时的查询方式

    数据库中某一列的值为 使用IN查询是无法查询到数据的,只能查询到IN(2)或者IN(2,3)  查询结果: , style_id) 正确方式:使用FIND_IN_SET函数 , style_id) , ...

  4. C语言 字符串大小写转换 自定义函数

    #include <stdio.h>#include <stdlib.h>#include <string.h> char * strtolower(char * ...

  5. 18 Issues in Current Deep Reinforcement Learning from ZhiHu

    深度强化学习的18个关键问题 from: https://zhuanlan.zhihu.com/p/32153603 85 人赞了该文章 深度强化学习的问题在哪里?未来怎么走?哪些方面可以突破? 这两 ...

  6. Facebook ads_Business Manager

    xmind 下载链接

  7. 【转载】谈谈自己对REST、SOA、SOAP、RPC、ICE、ESB、BPM知识汇总及理解

    转载自:https://blog.csdn.net/tantexian/article/details/48196453 SOA: 维基百科解释:SOA:面向服务的软件架构(Service Orien ...

  8. 5、iptables之nat

    iptables: 显式扩展.网络防火墙 显式扩展:multiport, iprange, string, time, connlimit, limit, state state:无关是哪种协议 /p ...

  9. 【Selenium2】【Jenkins】

    1. 下载Tomcat ,Windows7 环境,http://tomcat.apache.org/  我下载的是版本8 2. 下载Jenkins,Windows7 环境,http://jenkins ...

  10. 【Python】【有趣的模块】【requests】【一】HTTP头信息总结

    [HTTP请求 == 请求行 + 消息报头 + 请求正文 ] 请求行:Method Request-URL HTTP-Version CRLF HTTP协议定义了许多与服务器交互的方法 ① PUT:请 ...