IOI 98称号。然后,它似乎没有很困难。即使我能做到这一点微弱的残留物。所有的button按两次不按,高达因此实际上总的等效按4二级,首先C往下<=4,则搜索将能直接照射,总共只有16状态(事实上,没有),需要注意的是重判和订购,我们会处理的话非常快的二进制。= =不幸的是,我不会,转字符串。假设数据大点直接就挂了= =

/*
ID:kevin_s1
PROG:lamps
LANG:C++
*/ #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <cmath>
#include <bitset>
#include <strstream> using namespace std; //gobal variable====
int N;
int C;
int state[101];
int on, off;
int ons[101], offs[101];
int _count;
vector<long long> hash;
vector<string> result;
//================== //function==========
void print(){
for(int i = 1; i <= N; i++){
cout<<state[i];
}
cout<<endl;
} void init(){
for(int i = 1; i <= N; i++)
state[i] = 1;
} bool check(){
for(int i = 0; i < on; i++){
if(state[ons[i]] != 1){
return false;
}
}
for(int i = 0; i < off; i++){
if(state[offs[i]] != 0){
return false;
}
}
return true;
} void change(int i){
if(state[i] == 0)
state[i] = 1;
else if(state[i] == 1)
state[i] = 0;
} void Button1(){
for(int i = 1; i <= N; i++){
change(i);
}
} void Button2(){
for(int i = 1; i <= N; i+=2){
change(i);
}
} void Button3(){
for(int i = 2; i <= N; i+=2){
change(i);
}
} void Button4(){
for(int i = 0; (3*i + 1) <= N; i++){
int k = 3 * i + 1;
change(k);
}
} void Button(int i){
if(i == 1)
Button1();
if(i == 2)
Button2();
if(i == 3)
Button3();
if(i == 4)
Button4();
} void DFS(int i){
if(i > C)
return;
if(check()){
long long sum = 0;
for(int i = 1; i <= N; i++){
sum = sum * 10;
sum = sum + state[i];
}
vector<long long>::iterator iter = find(hash.begin(), hash.end(), sum);
if(iter == hash.end()){
_count++;
hash.push_back(sum);
string str;
for(int i = 1; i <= N; i++){
char ch = state[i] + 48;
str = str + ch;
}
result.push_back(str);
}
}
for(int j = 1; j <= 4; j++){
Button(j);
DFS(i + 1);
Button(j);
}
return;
} //================== int main(){
freopen("lamps.in","r",stdin);
freopen("lamps.out","w",stdout);
cin>>N;
cin>>C;
on = 0, off = 0;
_count = 0;
int _on, _off;
while(cin>>_on && _on != -1){
ons[on++] = _on;
}
while(cin>>_off && _off != -1){
offs[off++] = _off;
}
init();
while(C > 4){
C = C - 2;
}
DFS(0);
sort(result.begin(), result.end(), less<string>());
vector<string>::iterator iter = result.begin();
for(;iter != result.end(); iter++){
cout<<*iter<<endl;
}
if(_count == 0){
cout<<"IMPOSSIBLE"<<endl;
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

USACO lamps的更多相关文章

  1. USACO 2.2 Party Lamps 派对灯 (lamps)

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

  2. 【USACO 2.2】Party Lamps

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

  3. USACO Section 2.2: Party Lamps

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

  4. USACO Party Lamps 【Binary code solvution】【规律】

    写这道题目的时候遇到了一个令人诧异的问题,就是平台上跑来的结果和我本机跑起来的结果不一样. 后来Debug了之后才发现是我数组开小了,只开到100 的数组竟然都去访问他170位的地址肯定要跪成翔啊.. ...

  5. USACO Section2.2 Party Lamps 解题报告 【icedream61】

    lamps解题报告------------------------------------------------------------------------------------------- ...

  6. USACO Party Lamps

    题目大意:一排灯有n个,有4种开关,每种开关能改变一些灯现在的状态(亮的变暗,暗的变亮)现在已知一些灯的亮暗情况,问所以可能的情况是哪些 思路:同一种开关开两次显然是没效果的,那么枚举每个开关是否开就 ...

  7. POJ 1176 Party Lamps&& USACO 2.2 派对灯(搜索)

    题目地址 http://poj.org/problem?id=1176 题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都 ...

  8. Luogu USACO Training 刷水记录

    开个坑记录一下刷USACO的Training的记录 可能会随时弃坑 只有代码和做法简述 可能没有做法简述 [USACO1.1]你的飞碟在这儿Your Ride Is He… 模拟,细节已忘 #incl ...

  9. luoguP1468 派对灯 Party Lamps x

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

随机推荐

  1. SQLServer2008收缩数据库日志

    -- Set to SIMPLE mode ALTER DATABASE [DATABASE_NAME] SET RECOVERY SIMPLE; -- Shrink the db ); -- Set ...

  2. 创建DBLink语句

    --linkName DBLink名 --username 用户名 --password 密码 --tns TNS配置字符串 create database link &linkName co ...

  3. cocoapods安装失败

    ERROR:  While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the ...

  4. 【C#学习笔记】一、基础知识

    1.1数据类型(P43) 类型 别名 允许的值 sbyte System.SByte -128~127 byte System.Byte 0~255 short System.Int16 -32768 ...

  5. Linux(Debian)上安装Redis教程

    -- 第一步下载文件到该目录 cd /usr/local/src wget http:.tar.gz 解压 tar xzf redis.tar.gz -- 第二步编译安装 make make all ...

  6. 基于jq插件开发及弹窗实例

    基于jq的插件开发是什么鬼,$.fn是什么鬼,我在实际工作中也遇到过这个问题,下面就让我们一起来看一看这些都是什么鬼. 首先我们介绍$.fn. $.fn是指jquery的命名空间,加上fn上的方法及属 ...

  7. C# 多线程编程 ThreadStart ParameterizedThreadStart

    原文地址:http://club.topsage.com/thread-657023-1-1.html 在实例化Thread的实例,需要提供一个委托,在实例化这个委托时所用到的参数是线程将来启动时要运 ...

  8. groovy构建和解析xml文件

    原文链接:http://www.ibm.com/developerworks/cn/java/j-pg05199/ 代码示例: 构建xml文件: def static createXmlFile(){ ...

  9. [HttpClient]HttpClient简介

    1. 前言 HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java应用程序需要直接通过 HTTP 协议来访问网路资源.虽然在 JDK 的 java net包中已 ...

  10. HTML cellpadding与cellspacing属性

    单元格(cell) -- 表格的内容 单元格边距(表格填充)(cellpadding) -- 代表单元格外面的一个距离,用于隔开单元格与单元格空间 单元格间距(表格间距)(cellspacing) - ...