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 ...
随机推荐
- undefined reference to `vtable for MyColor'
MyColor是新建的类,原因是使用了QObject,但是系统没有反应过来 解决:从工程删除,再添加进去[QtCreator]
- SpringBoot 超时设置
1.RestTemplate超时 设置配置HttpComponentsClientHttpRequestFactory中的RequestConfig属性 RestTemplateConfig: imp ...
- [转]web高级开发的成长之路
读了这篇文章之后感觉蛮受启发的,在此分享一下,献给和我一样处于困惑的朋友. 正文如下: 本人也是coding很多年,虽然很失败,但也总算有点失败的心得,不过我在中国,大多数程序员都是像我一样,在一直走 ...
- sublime配置 sublimecondeintel 分号后不要提示
https://github.com/SublimeCodeIntel/SublimeCodeIntel/issues/461 Thanks to @catgsmith ,I find a simil ...
- 51nod 1351 吃点心(贪心)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1351 题意: 思路: 要么先选low值大的,要么先选high值大的,分两 ...
- 使用openlayers 3 在线加载天地图及GeoServer发布的地图
使用openlayers3来加载天地图卫星图和标注图层,GeoServer发布地图,一并用openlayers测试加载出来,顺便实现了7种地图控件.下面直接贴代码: <!DOCTYPE html ...
- Intellij idea 添加浏览器
最近的项目要做一个海康的网页端的监控,需要下载海康的插件,但是试验了一下,Chrome和IE的都不支持插件的显示,只有搜狗的显示,但是Idea的默认浏览器里面没有,所以要添加一个默认的浏览器 方法很简 ...
- 解决在Vue项目中时常因为代码缩进导致页面报错的问题
前言 如果我们初次使用vue-cli来构建单页SPA应用,在撸代码的过程中有可能会遇到这种因为代码缩进导致 页面报错的问题,导致我们烦不胜烦.接下来我们就来看一看如何解决这个小问题... erro原因 ...
- 基于iOS用CoreImage实现人脸识别
2018-09-04更新: 很久没有更新文章了,工作之余花时间看了之前写的这篇文章并运行了之前写的配套Demo,通过打印人脸特征CIFaceFeature的属性,发现识别的效果并不是很好,具体说明见文 ...
- 学习笔记56—Endnote参考文献格式调整
论文写作