party lamps(dfs优化+规律枚举)
Problem description:
To brighten up the gala dinner of the IOI'98 we have a set of N coloured lamps numbered from
1 to N. The lamps are connected to four buttons:
button 1 -- when this button is pressed, all the lamps change their state: those that are ON are turned OFF and those that are OFF are turned ON.
button 2 -- changes the state of all the odd numbered lamps.
button 3 -- changes the state of all the even numbered lamps.
button 4 -- changes the state of the lamps whose number is of the form 3K+1 (with K >= 0), i.e., 1,4,7,...
There is a counter C which records the total number of button presses.
When the party starts, all the lamps are ON and the counter C is set to zero.
You are given the value of counter C and information on the final state of some of the lamps. Write a program to determine all the possible final configurations of the N lamps that are consistent with the given information, without repetitions.
汉化:
为了让IOI'98的晚宴更加精彩,我们有一套编号为的N色灯。
1到N。灯与四个按钮相连:
按钮1——当按下此按钮时,所有的灯都会改变其状态:打开的灯关闭,关闭的灯打开。
按钮2——改变所有奇数灯的状态。
按钮3——改变所有偶数灯的状态。
按钮4——改变灯的状态,灯的编号形式为3K+1(k>=0),即1,4,7,…
有一个计数器C记录按钮按下的总数。
聚会开始时,所有的灯都亮着,计数器C调零。
您将获得计数器C的值和一些灯的最终状态信息。编写一个程序来确定n个灯的所有可能的最终配置,这些配置与给定的信息一致,无需重复。
Input:
Your program is to read from standard input. The input contains four lines, describing the number N of lamps available, the number C of button presses, and the state of some of the lamps in the final configuration.
The first line contains the number N and the second line the final value of counter C. The third line lists the lamp numbers you are informed to be ON in the final configuration, separated by one space and terminated by the integer -1. The fourth line lists the lamp numbers you are informed to be OFF in the final configuration, separated by one space and terminated by the integer -1.
The parameters N and C are constrained by:
10 <= N <= 100
1 <= C <= 10000
The number of lamps you are informed to be ON, in the final configuration, is less than or equal to 2.The number of lamps you are informed to be OFF, in the final configuration, is less than or equal to 2.
汉化:
您的程序将从标准输入中读取。输入包含四行,描述可用灯的数量n、按钮按下的数量c以及最终配置中某些灯的状态。
第一行包含数字n,第二行包含计数器c的最终值。第三行列出在最终配置中通知您要打开的灯号,用一个空格分隔并以整数-1结束。第四行列出了在最终配置中通知您要关闭的灯号,用一个空格分隔并以整数-1结束。
参数n和c受以下约束:
10<=n<=100
1<=c<=10000
在最终配置中,通知您要打开的灯的数量小于或等于2。在最终配置中,通知您要关闭的灯的数量小于或等于2。
Output:
Your program is to write to standard output. The output must contain all the possible final configurations (without repetitions) of all the lamps. There is at least one possible final configuration. Each possible configuration must be written on a different line. Each line has N characters, where the first character represents the state of lamp 1 and the last character represents the state of lamp N. A 0 (zero) stands for a lamp that is OFF, and a 1 (one) stands for a lamp that is ON. Configurations should be listed in binary ascending order.
汉化:
您的程序将写入标准输出。输出必须包含所有灯的所有可能最终配置(无重复)。至少有一个可能的最终配置。每个可能的配置都必须写在不同的行上。每行有n个字符,其中第一个字符表示灯1的状态,最后一个字符表示灯n的状态。0(零)表示灯关闭,1(一)表示灯打开。配置应按二进制升序列出。
Sample Input
10
1
-1
7 -1
Sample Output
0000000000
0101010101
0110110110 分析:
1.题意理解概括与规律探寻详见博文:https://blog.csdn.net/wmn_wmn/article/details/7382242
2.详细分析见博文:https://blog.csdn.net/ly59782/article/details/52252329
party lamps(dfs优化+规律枚举)的更多相关文章
- zoj 1008 暴力枚举求解dfs+优化
/* 现将相同的合并计数. 再枚举判断是否符合当cou==n*n是符合就退出 */ #include<stdio.h> #include<string.h> #define N ...
- 【递推】【DFS】【枚举】Gym - 101246C - Explode 'Em All
网格里放了一些石块,一个炸弹能炸开其所在的行和列.问炸光石块至少要几个炸弹. 枚举不炸开的行数,则可以得出还要炸开几列. 为了不让复杂度爆炸,需要两个优化. 先是递推预处理出f(i)表示i的二进制位中 ...
- [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)
Generalized Palindromic Number Time Limit: 2 Seconds Memory Limit: 65536 KB A number that will ...
- Tinkoff Challenge - Elimination Round B. Igor and his way to work(dfs+优化)
http://codeforces.com/contest/793/problem/B 题意:一个地图,有起点和终点还有障碍点,求从起点出发到达终点,经过的路径上转弯次数是否能不超过2. 思路: 直接 ...
- BZOJ3436: 小K的农场(差分约束裸题&DFS优化判环)
3436: 小K的农场 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2111 Solved: 986[Submit][Status][Discus ...
- 【DFS】【枚举】Gym - 101246G - Revolutionary Roads
给你一张有向图,问你将任意一条边变成双向后,所能得到的最大强连通分量的大小. 缩点之后,预处理can(i,j)表示i能到j. 之后枚举每一条边(u,v),再枚举其他所有点t,如果can(u,t) &a ...
- 洛谷 P1618 三连击(升级版)【DFS/next_permutation()/技巧性枚举/sprintf】
[链接]:https://www.luogu.org/problemnew/show/P1618 题目描述 将1,2,…,9共9个数分成三组,分别组成三个三位数,且使这三个三位数的比例是A:B:C,试 ...
- POJ-1190-生日蛋糕-DFS(深搜)-枚举-多重剪枝
题目链接: 这个题目非常好,有难度:能够好好的多做做: #include<iostream> #include<string> #include<cstdio> # ...
- UVA - 818 Cutting Chains(切断圆环链)(dfs + 二进制法枚举子集)
题意:有n个圆环(n<=15),已知已经扣在一起的圆环,现在需要打开尽量少的圆环,使所有圆环可以组成一条链. 分析:因为不知道要打开哪个环,如果列举所有的可能性,即枚举打开环的所有子集,最多才2 ...
随机推荐
- C#常规TcpListener
1.Xaml <Window x:Class="Server.MainWindow" xmlns="http://schemas.microsoft.com/win ...
- java学习笔记之反射—Class类实例化和对象的反射实例化
反射之中所有的核心操作都是通过Class类对象展开的,可以说Class类是反射操作的根源所在,但是这个类的实例化对象,可以采用三种方式完成. java.lang.Class类的定义: public f ...
- MySql快速入门(四)
在之前我们对MySql已经有了基本的了解,接下来我们就来接触MySql的分库分表,请往下阅读: 分库分表之MyCat实现 分库分表介绍: 随着微服务这种架构的兴起,我们应用从一个完整的大的应用,切分为 ...
- 图片,base64 互转
import sun.misc.BASE64Decoder; import java.io.FileOutputStream; import java.io.OutputStream; /** * @ ...
- Milking Time POJ - 3616 dp 感觉像背包
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> us ...
- CodeForces 1144C
链接 https://vjudge.net/problem/CodeForces-1144C #include<bits/stdc++.h> using namespace std; in ...
- cf 手机短信问题
题目链接:https://vjudge.net/contest/331120#problem/C 题目:你有一部手机,最多显示k个人发的信息,现在收到n条信息,有可能人是相同的人发的.最新的要顶置,当 ...
- 酷卓 一键ROOT教程
待编辑,还没写完 哈哈 酷卓 一键ROOT教程 首先简单介绍下酷卓. 酷卓由我个人开发,主要为了用户获取ROOT简单化,傻瓜化.酷卓获取方式:加QQ群 766969447 群文件下载就行 1. 手动选 ...
- Linux 环境c++ 编码转换
#include <iconv.h> //代码转换:从一种编码转为另一种编码 static int CodeConvert(char *from_charset,char *to_char ...
- Eclipse的Errors in required projec(s)问题
在Eclipse中运行代码时出现Errors exist in required project(s)弹窗提示,但是当前类并无错误,点击Proceed当前类仍然可以运行 错误展示: Errors ex ...