p1468 Party Lamps
就是模拟。同一个开关按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的更多相关文章
- 【搜索】P1468 派对灯 Party Lamps
P1468 派对灯 Party Lamps 我们来分析一下对灯的操作 1.对所有灯的,这时吧所有灯看成一个整体 2.奇偶数的操作,这时可以把每两个数看成一个循环节 3.对3X+ 1的操作,这时可以把每 ...
- luogu P1468 派对灯 Party Lamps
题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄 ...
- P1468 派对灯 Party Lamps(BIG 模拟)
题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄 ...
- luoguP1468 派对灯 Party Lamps x
P1468 派对灯 Party Lamps 题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当 ...
- 【USACO 2.2】Party Lamps
四种开关,n盏灯,1:改变所有灯状态,2:改变奇数灯状态,3:改变偶数灯状态,4:改变3k+1灯状态 给你按开关的总次数c和部分灯限制条件(开或关),一开始都是开着的.($c \leq 10000,n ...
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- poj 1176 Party Lamps
http://poj.org/problem?id=1176 Party Lamps Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- USACO Section 2.2: Party Lamps
这题有个小技巧, 按一个键两次等于没按,所以如果depsum > 16的话其实不用做深搜到depsum次,而只要16次就可以了. /* ID: yingzho1 LANG: C++ TASK: ...
- UVA 12382 Grid of Lamps 贪心
题目链接: C - Grid of Lamps Time Limit:1000MSMemory Limit: 0KB 问题描述 We have a grid of lamps. Some of the ...
随机推荐
- CSS层叠样式表--找到标签
0 怎么学习CSS 1 CSS的四种引入方式 2 CSS的四种基本选择器 3 属性选择器 4 CSS伪类 5 CSS选择器优先级 6 CSS的继承性 怎么学习CSS 1.怎么找到标签(CSS选择器) ...
- Redis常用操作大全和Python操作Redis
简单使用 utils.py import redis POOL=redis.ConnectionPool(host='127.0.0.1',port=6379) view.py 第一种方式 (通用方式 ...
- Docker 入门指南——Dockerfile 指令
COPY 复制文件 格式: COPY [--chown=<user>:<group>] <源路径>... <目标路径> 源路径可以是多个,甚至可以使通配 ...
- Ubuntu 使用unzip解压乱码的问题
由于win使用的是GBK编码,在win下打包zip的压缩文件在ubuntu下使用unzip解压会出现乱码的问题. 解决方案: 换软件,不用unzip,使用unar 18.04是默认安装的,如果没有默认 ...
- 3. Elements of a Test Plan
https://jmeter.apache.org/usermanual/test_plan.html This section describes the different parts of a ...
- 【Spring Security】三、自定义数据库实现对用户信息和权限信息的管理
一 自定义表结构 这里还是用的mysql数据库,所以pom.xml文件都不用修改.这里只要新建三张表即可,user表.role表.user_role表.其中user用户表,role角色表为保存用户权限 ...
- 比较好的MySQL索引原理
MySQL索引原理及慢查询优化 - 美团技术团队 https://tech.meituan.com/2014/06/30/mysql-index.html
- html 之 body topmargin、leftmargin、rightmargin、bottomnargin
基本语法 <body topmargin=value leftmargin=value rightmargin=value bottomnargin=value> 语法说明 通过设置top ...
- WebLogic调用WebService提示Failed to localize、Failed to create WsdlDefinitionFeature
在本地Tomcat环境下调用WebService正常,但是部署到WebLogic环境中,则提示警告:[Failed to localize] MEX0008.PARSING_MDATA_FAILURE ...
- 论文笔记:Learning Dynamic Memory Networks for Object Tracking
Learning Dynamic Memory Networks for Object Tracking ECCV 2018Updated on 2018-08-05 16:36:30 Paper: ...