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. 说说RMAN里的obsolete

    RMAN> report obsolete; RMAN retention policy will be applied to the commandRMAN retention policy ...

  2. iOS 中的传值方式

    一. 属性传值   将A页面所拥有的信息通过属性传递到B页面使用 很常用的传值,也很方便,但是要拿到类的属性.例如: B页面定义了一个naviTitle属性,在A页面中直接通过属性赋值将A页面中的值传 ...

  3. Javascript数组方法探究一二

    1. Array.prototype.slice方法 数组的 slice 方法通常用来从一个数组中抽取片断.不过,它还有将“类数组”(比如arguments和​HTMLCollection​)转换为真 ...

  4. JavaScript--垃圾回收器

    垃圾回收: 释放不再被任何变量引用的对象 垃圾回收器: 专门记录对象的引用次数,并回收不再被引用的对象的程序. 垃圾回收器和主程序并行在后台执行 垃圾回收器会为每个对象创建一个引用计数器(counte ...

  5. vi文本编辑器

    vi文本编辑器分为3个模式: 命令模式 插入模式 ex模式 在命令模式下我们可以使用一下功能 o 插入新的行 u 撤销 n yy  复制n行 p 粘贴 / 查找 i 进入插入模式 exc到命令模式 e ...

  6. javascript 读取内联之外的样式(style、currentStyle、getComputedStyle区别介绍) (转载)

    样式表有三种方式: 内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有效.   (也称作“内联样式”) 内部样式(internal Style Sheet):是写在 ...

  7. [Python笔记]第四篇:内置函数

    本篇主要内容:内置函数 函数 参考:https://docs.python.org/3.5/library/functions.html 内置函数列表 一.数学运算类 abs(x)求绝对值 >& ...

  8. IOS UITableView NSIndexPath属性讲解

    IOS UITableView NSIndexPath属性讲解   查看UITableView的帮助文档我们会注意到UITableView有两个Delegate分别为:dataSource和deleg ...

  9. How to use PhotoshopApplication in maxscript

    未完待续 ps_app= createOLEObject "Photoshop.Application" ps_app.Load "d:\\test\\aaa.tga&q ...

  10. Spring中使用log4j随笔

    web.xml中的配置: <!--由Sprng载入的log4j配置文件位置--> <context-param> <param-name>log4jConfigLo ...