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 ...
随机推荐
- P1339 热浪【最短路】
#include <bits/stdc++.h> #define dbg(x) cout << #x << "=" << x < ...
- GYCTF Node game
考点: NodeJS 代码审计 SSRF 请求夹带 复现: 不太懂js,先留着吧,学懂了再记录
- (1)-Android学习笔记之:初识Android系统架构和项目结构
Android系统架构 Android程序结构 创建一个Android项目,为初学便于理解,将程序项目结构切换为Project模式,项目结构如下 .gradle和.idea:这两个目录下放的都是And ...
- git配置多仓库
git配置多仓库 github , gitee , coding , gitlab , gitlab.company ..... 真TM多 . 真TM多 . 真TM多 . 生成ssh 生成ssh 密钥 ...
- java - 并发集合 Vector、synchronizedCollection、CopyOnWriteArrayList之间的区别。
概要 JDK中提供ArrayList集合方便我们对集合内元素进行增删改查,但是ArrayList为了能够在单线程中快速进行操作其设计并不支持多线程进行操作.ArrayList在多线程环境下可能会产生j ...
- FZU-Problem 2150 Fire Game(两点bfs)
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns) ...
- C++-蓝桥杯-矩阵乘法[快速幂]
忘了改矩阵的大小居然还有33分,我醉了 #include <cstdio> ; struct Matrix{int a[N][N];}; int n,m; Matrix A,O,I; Ma ...
- 解决并发问题的CAS思想及原理
全称为:Compare and swap(比较与交换),用来解决多线程并发情况下使用锁造成性能开销的一种机制: 原理思想:CAS(V,A,B),V为内存地址,A为预期原值,B为新值.如果内存地 ...
- 分类问题(三)混淆矩阵,Precision与Recall
混淆矩阵 衡量一个分类器性能的更好的办法是混淆矩阵.它基于的思想是:计算类别A被分类为类别B的次数.例如在查看分类器将图片5分类成图片3时,我们会看混淆矩阵的第5行以及第3列. 为了计算一个混淆矩阵, ...
- Unable to connect to Elasticsearch at http://elasticsearch:9200. statu red Kibana 安装
解决方案 docker run -d -p 5601:5601 --link elasticsearch -e "elasticsearch_url=容器ip:9200" --na ...