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 ...
随机推荐
- 阿里云oss 直传
sts获取 参考https://help.aliyun.com/document_detail/28792.html?spm=a2c4g.11186623.6.786.6fb238dfI9iiqA 配 ...
- CPPU OJ | 开发日志
2019.12.18 ~ 2019.12.22 用腾讯云的学生服务器测试搭建OJ(踩了无数的坑) 2019.12.25 ~ 2019.12.28 在模管中心办理申请虚拟服务器的手续 2019.12.3 ...
- 百度网盘无vip高速下载的方法
我拿的是谷歌浏览器做实验 首先下载一个可以改user-agent的插件 我chorm里面下载的是User-Agent Switcher for Chrome插件 将百度网盘的url地址中的baidu. ...
- 在线教育厮杀惨烈,51Talk一家独大之后,却仍是持续亏损?
编辑 | 于斌 出品 | 于见(mpyujian) 来自51Talk在线少儿英语专业的学生陈和涛已经成为最近<快乐营大本营>的一个亮点.该学生应邀以流利的英语在台上作自我介绍,并与51Ta ...
- jenkins Exec exit status not zero. Status [-1]
jenkins是使用ssh连接服务器后,如果使用grep获取进程并kill时,会jenkins Exec exit status not zero. Status [-1],解决办法:在获取进程时,使 ...
- java多线程CountDownLatch
先上一个介绍:https://blog.csdn.net/shihuacai/article/details/8856370 用视频https://www.bilibili.com/video/av8 ...
- 更新了svn 后,某个文件多了几个副本如:xxx.r1 xxx.r3 xxx.mine等,正常文件名xxx
分析:更新了svn后 原因: 是的,修改完后,还要把问号文件全部删除,再重新提交(话说,你的SVN名字和我的名字一样,wk).你每次修改之前都更新一下最好了.
- Vue+ESLint+Git钩子函数pre-commit配置教程
一.创建Vue项目eslint-standard vue create eslint-standard 二.创建.eslintrc.* 删除package.json中的eslintConfig配置 我 ...
- mybatis(五):源码分析 - 获取boundsql流程
- 虫师自动化测试robot Framework 框架的学习
1.python关键字的定义 #coding=utf-8 def add(a,b): return a+b if __name__ == "__main__": c = add(4 ...