USACO section 2.2 Party Lamps

3D Slicer的学习(二) 图像的分割 先对不同层级标注,然后点击Fill between slices -> Initialize -> Apply拖动层级颜色区域就会变成连续自适应的动态变化区域。如图,点击Level tracing,在图像上放置鼠标,会显示可能想要选中区域的轮廓,点击鼠标右键会将其显示为蓝色。然后点击Grow from seeds -> Initialize -> Apply,显示3D之后会自动扩展到其他位置的相同部位,从而展示整个部位。如图为copy之后,将黄色区域的颜色复制到原本的绿色区域。 阅读详情
Party Lamps
IOI 98

To brighten up the gala dinner of the IOI'98 we have a set of N (10 <= N <= 100) colored 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 3xK+1 (with K>=0), i.e., 1,4,7,...

A counter C 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 (0 <= C <= 10000) and the final state of some of the lamps after some operations have been executed. Write a program to determine all the possible final configurations of the N lamps that are consistent with the given information, without repetitions.

PROGRAM NAME: lamps

INPUT FORMAT

 

Line 1:N
Line 2:Final value of C
Line 3:Some lamp numbers ON in the final configuration, separated by one space and terminated by the integer -1.
Line 4:Some lamp numbers OFF in the final configuration, separated by one space and terminated by the integer -1.

No lamp will be listed twice in the input.

SAMPLE INPUT (file lamps.in)

10
1
-1
7 -1

In this case, there are 10 lamps and only one button has been pressed. Lamp 7 is OFF in the final configuration.

OUTPUT FORMAT

Lines with all the possible final configurations (without repetitions) of all the lamps. 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. The lines must be ordered from least to largest (as binary numbers).

If there are no possible configurations, output a single line with the single word `IMPOSSIBLE'

SAMPLE OUTPUT (file lamps.out)

0000000000
0101010101
0110110110

In this case, there are three possible final configurations:

  • All lamps are OFF
  • Lamps 1, 4, 7, 10 are OFF and lamps 2, 3, 5, 6, 8, 9 are ON.
  • Lamps 1, 3, 5, 7, 9 are OFF and lamps 2, 4, 6, 8, 10 are ON.

解题思路:灯的开关有四种方式,每种方式只能使用一次,因为使用两次和不使用是一样的。因此总的使用情况有2^4种,依次枚举找出符合条件的,再按从大到小排序输出即可。我是用个类存bool行表状态。因为情况最多只有16种,因此取bool型的前四位转化为十进制来排序,最后输出即可。

另外还有一点就是开关使用次数。只要前面枚举时看使用的开关数小于等于题目要求数并且使用开关数于题目要求数同奇偶即可。(因为使用两次一样的开关和不使用一样)

 

/*
ID:nealgav1
PROG:lamps
LANG:C++
*/
#include<fstream>
#include<algorithm>
#include<cstring>
using namespace std;
const int mm=230;//灯的数量
class node
{public:
  int num;//用来排序的,取vis[]前四位转化为十进制
  bool vis[mm];
  node()
  { num=0;
    memset(vis,1,sizeof(vis));//初始状态为全开
  }
}f[21];
node _ans[21];//存最后的结果
//bool vis[21][mm];
int on[mm],off[mm],ans[mm],lans,lon,loff;//最后状态的开关要求
int _num;
int n,c;
void button(int num,int x)//四种开关操作
{
  if(x==1)
  {
    for(int i=0;i<n;i++)
    f[num].vis[i]^=1;
  }
  else if(x==2)
  {
    for(int i=0;i<n;i+=2)
    f[num].vis[i]=f[num].vis[i]^1;
  }
  else if(x==3)
  {
    for(int i=1;i<n;i+=2)
    f[num].vis[i]=f[num].vis[i]^1;
  }
  else
  { for(int i=0;i<n;i+=3)
    f[num].vis[i]=f[num].vis[i]^1;
  }
}
int lowbit(int x)
{
  return x&(-x);
}
bool look_up(int num,int x)//判断状态可行性
{
  int nu=1,km=0;
  while(x)
  {
    if(x&1)
    {
      button(num,nu);km++;
    }
    x>>=1;nu++;
  }
  if(km>c||(km&1)!=(c&1))//若使用开关数大于要求或使用开关数与要求奇偶性不同
  return 0;              //则不符合条件
  for(int i=0;i<lon-1;i++)
  if(!f[num].vis[on[i]-1])
  return 0;
  for(int i=0;i<loff-1;i++)
  if(f[num].vis[off[i]-1])
  return 0;
  return 1;
}
void charge()
{
  lans=0;
  for(int i=0;i<16;i++)//枚举16种状态
  {
    if(look_up(i,i))
    {
      ans[lans++]=i;
    }
  }
}
bool cmp(node a,node b)
{
  return a.num<b.num;
}
void b_sort()//排序
{  _num=0;
  for(int i=0;i<lans;i++,_num++)
  {
   _ans[_num]=f[ans[i]];
   for(int j=0;j<8;j++)
   { _ans[_num].num<<=1;
     if(_ans[_num].vis[j])
    _ans[_num].num+=1;

   }
  }
  //cout<<"lans "<<lans<<"lans\n";
  sort(_ans,_ans+_num,cmp);
}
int main()
{
  ifstream cin("lamps.in");
  ofstream cout("lamps.out");
  cin>>n>>c;
  for(lon=0;on[lon-1]!=-1;lon++)
  {
    cin>>on[lon];
  }
  for(loff=0;off[loff-1]!=-1;loff++)
  {
    cin>>off[loff];
  }
  charge();
  b_sort();
  if(_num<=0)cout<<"IMPOSSIBLE\n";
  else
  for(int i=0;i<_num;i++)
  {for(int j=0;j<n;j++)
   cout<<_ans[i].vis[j];
   //cout<<_ans[i].num<<"\n";
   cout<<"\n";
  }
}


 

 

 

USER: Neal Gavin Gavin [nealgav1]
TASK: lamps
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.011 secs, 3356 KB]
   Test 2: TEST OK [0.000 secs, 3356 KB]
   Test 3: TEST OK [0.000 secs, 3356 KB]
   Test 4: TEST OK [0.000 secs, 3356 KB]
   Test 5: TEST OK [0.000 secs, 3356 KB]
   Test 6: TEST OK [0.000 secs, 3356 KB]
   Test 7: TEST OK [0.000 secs, 3356 KB]
   Test 8: TEST OK [0.011 secs, 3356 KB]

All tests OK.

Your program ('lamps') produced all correct answers! This is your submission #2 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
10
0
-1
-1
------- test 2 ----
10
0
-1
1 -1
------- test 3 ----
20
3
-1
1 3 5 -1
------- test 4 ----
50
100
1 -1
-1
------- test 5 ----
75
250
-1
-1
------- test 6 ----
100
8394
1 7 13 19 25 31 37 43 49 55 -1
64 -1
------- test 7 ----
100
2000
31 86 23 -1
42 -1
------- test 8 ----
100
8950
-1
-1
Keep up the good work!


Thanks for your submission!

Party LampsRuss Cox

There are a number of insights required for this problem.

The main insight is that no matter which switches get pressed, the light pattern will repeat every six lamps. Another insight is that the order of switch presses does not matter, and that pressing a switch twice is the same as not pressing a switch at all.

Any even number of switch presses greater than four might as well just be four switch presses, and and any odd number greater than three might as well just be three presses.

We can treat the light information as describing only the first six lamps (by treating lamp n as lamp (n mod 6)), and only try pressing each switch once or not at all.

To maintain the actual information about which lights are on, we use an integer holding six bits. The least significant bit is light 6, the next least is light 5, and so on. This has the effect that treating these bit strings as normal numbers sorts the same way that we need to print them.

Switches are represented as bit vectors that say which lights get toggled.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#define MAXLAMP	6
#define LAMPMASK	((1<<MAXLAMP)-1)

int nlamp;
int nswitch;
int ison;
int known;

int poss[1<<MAXLAMP];

int flip[4] = {
    LAMPMASK,		/* flip all lights */
    LAMPMASK & 0xAA, 	/* flip odd lights */
    LAMPMASK & 0x55,	/* flip even lights */
    LAMPMASK & ((1<<(MAXLAMP-1))|(1<<(MAXLAMP-4)))	/* lights 1, 4 */
};

/*
 * Starting with current light state ``lights'', flip exactly n switches
 * with number >= i.
 */
void
search(int lights, int i, int n)
{
    if(n == 0) {
	if((lights & known) == ison)
	    poss[lights] = 1;
	return;
    }

    for(; i<4; i++)
	search(lights ^ flip[i], i+1, n-1);
}

void
printseq(FILE *fout, int lights)
{
    int i;
    char s[100+1];

    for(i=0; i<nlamp; i++)
	s[i] = (lights & (1<<(MAXLAMP-1 - i%MAXLAMP))) ? '1' : '0';
    s[nlamp] = '\0';
    fprintf(fout, "%s\n", s);
}

void
main(void)
{
    FILE *fin, *fout;
    int a, i, impossible;

    fin = fopen("lamps.in", "r");
    fout = fopen("lamps.out", "w");
    assert(fin != NULL && fout != NULL);

    fscanf(fin, "%d %d", &nlamp, &nswitch);

    for(;;) {
	fscanf(fin, "%d", &a);
	if(a == -1)
	    break;
	a = MAXLAMP-1 - (a-1) % MAXLAMP;
	ison |= 1<<a;
	known |= 1<<a;
    }

    for(;;) {
	fscanf(fin, "%d", &a);
	if(a == -1)
	    break;
	a = MAXLAMP-1 - (a-1) % MAXLAMP;
	assert((ison & (1<<a)) == 0);
	known |= 1<<a;
    }

    if(nswitch > 4)
	if(nswitch%2 == 0)
	    nswitch = 4;
	else
	    nswitch = 3;

    for(; nswitch >= 0; nswitch -= 2)
	    search(LAMPMASK, 0, nswitch);

    impossible = 1;
    for(i=0; i<(1<<MAXLAMP); i++) {
	if(poss[i]) {
	    printseq(fout, i);
	    impossible = 0;
	}
    }
    if(impossible)
	fprintf(fout, "IMPOSSIBLE\n");

    exit(0);
}

 

 

 

rag综述——RAG技术发展流程、最新技术挑战与系统级优化 RAG技术发展综述:本文系统梳理了检索增强生成(RAG)技术的演进历程,从2017年开放域问答中的早期探索,到2020年正式提出RAG架构并与大模型深度融合,再到2025年向系统化、可信化和智能体化发展。当前RAG面临检索可靠性、系统效率和生成可信度三大核心挑战,解决方案包括领域自适应训练、强化语义编码、迭代检索策略等优化方向。未来RAG将向GraphRAG、SafeRAG等方向发展,从单纯性能优化转向构建可控、可审计的语言系统框架,成为高可靠大模型应用的基础设施。 阅读详情

相关推荐

在国产麒麟V10(arm64)上离线部署Docker 24.0.6和Compose 2.30.1,保姆级避坑实录

本文详细介绍了在国产麒麟V10(arm64)操作系统上离线部署Docker 24.0.6和Compose 2.30.1的完整流程,包括环境准备、架构认知、安装步骤、系统服务优化及生产环境加固。特别针对ARM64架构的兼容性问题提供了解决方案,帮助用户在信创环境中高效部署容器化技术。

weixin_30342209的博客 484

【USACO2.2.4】Party Lamps派对灯——杨子曰题目

【USACO2.2.4】Party Lamps派对灯——杨子曰题目 题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码。 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄灭,本来是关着的灯被点亮。 按钮2:当按下此按钮,将改变所有奇数号的灯。 按钮3:当按下此按钮,将改变所有偶数号的灯。 按钮4:当按...

杨子曰:代码是神奇的 797

从零到一:手把手教你用STM32F103C8T6打造个人专属开发板(附立创EDA工程与源码)

本文详细介绍了如何使用STM32F103C8T6微控制器从零开始设计和制作个人专属开发板。内容涵盖硬件选型、原理图设计、PCB布局、功能验证等全流程,并提供了立创EDA工程文件和源码,帮助开发者深入理解STM32开发板的硬件架构与设计要点。

weixin_26802933的博客 285

[USACO2.2]派对灯 Party Lamps 题解

洛谷原题链接:[USACO2.2]派对灯 Party Lamps - 洛谷 太细了太细了太细了!!!首先得想到多转4,然后是4转2,这是基本思路。代码实现更恶心好吧!首先得想到b[9][7]的各种情况,要想到6是循环节,然后进入主程序,第一个点就是当c==0但是还有关灯限制的是IMPOSSIBLE(其实可以有开灯限制,但是数据比较水,开灯限制没管也能过)第二个点是c=0但是没有关灯限制,此时输出全是1。接着进入主要循环,c==1的话根本不会有5,6,7三种情况,得特判去掉,最后就是还得判断虽然前面这几个点

HypnotizeG的博客 474

Slurm集群调度策略详解(1)-主调度

Slurm调度系统中针对作业的调度主要有三种,主调度,回填调度,GANG调度,这篇文章主要针对主调度进行解析。

h_m_l的博客 6030

eCognition易康面向对象分类批量选择样本,批量导出shp

可以的,使用这个工具条最右边那个三角尺manual editing toolbar,这是用来直接指定类别的,咱们可以拿它选完以后把指定的类别转成训练样本。另一个好处是,这个选出来的样本可以直接导出成shp,但select sample是不可以的,只能导出TTAMask也就是栅格掩膜。如果要导出shp,要在转之前导出。中间那条有点点的红线就是我的鼠标轨迹,只要碰到的对象就会全部选中,然后一点3的那个按钮就直接全部划分为林地了,十分丝滑。在弹出来的工作条里,首先选择你的类别,比如这里选一个forest。

qq_61845364的博客 4070

派对灯(poj1176 Party Lamps)

Description英文版 To brighten up the gala dinner of the IOI 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 th...

yxmbbd的博客 418

告别时钟树平衡噩梦:在Innovus中巧妙设置stop/ignore pin来优化分段时钟网络

本文深入探讨了在Innovus工具中利用stop/ignore pin优化分段时钟树网络的高阶技巧。针对数字IC后端设计中的时钟树平衡难题,详细解析了特殊引脚属性的战略应用场景和配置方法,帮助工程师有效解决SoC设计中复杂的时钟结构问题,显著提升时序收敛效率。

weixin_30836759的博客 289

party lamps(dfs优化+规律枚举)

Problem description: To brighten up the gala dinner of the IOI'98 we have a set of N coloured lamps numbered from1 to N. The lamps are connected to four buttons:button 1 -- when this button is...

banteng7670的博客 156

基于Simulink的PID控制防抱死制动系统(ABS)建模与仿真

防抱死制动系统(Anti-lock Braking System,简称ABS)是一种用于防止车辆在紧急制动时车轮完全抱死的技术。通过实时监测车轮速度并调节制动力,ABS能够显著提高车辆的制动性能和操控稳定性,从而减少交通事故的发生。PID(比例-积分-微分)控制器因其结构简单、性能稳定且易于实现而被广泛应用于ABS控制系统中。本项目旨在通过MATLAB/Simulink平台设计和验证一个基于PID控制的ABS系统,重点研究PID参数调优方法、系统动态响应特性以及制动过程中的滑移率控制能力。

MHD0815的博客 484

实战:RK3568 Android14 调试 ES8388 音频驱动 (MIC 篇)

这个板子的MIC设计使用了硬件自动切换方案,极大简化了软件层面的逻辑。我们不需要根据耳机插拔事件去编写复杂的路由切换代码,只需要守住 LIN1/RIN1 这一个入口,配置好增益,剩下的交给那颗 SGM3157 芯片即可。祝您的录音功能调试顺利!

qq_33427070的博客 1680

Party Lamps【DFS】

Party Lamps describe 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 presse...

Ursue的博客 236

飞牛fnNAS搭建私有云音乐库

本文介绍了在飞牛NAS上部署Navidrome音乐服务器的完整流程。首先创建音乐存储目录并安装Navidrome应用,然后配置管理员账号、语言设置和音乐路径。接着详细说明使用"音乐标签"软件刮削音乐元数据的方法,包括获取软件、导入音乐文件和自动匹配标签。针对远程访问需求,推荐使用ZeroTier实现内网穿透,并给出注册、创建网络及设备加入的具体步骤。最后介绍移动端使用"音流"APP连接Navidrome服务器的配置方法,实现手机端音乐播放。通过这套方案,用户可以搭建专

dgnankai的专栏 1823

USACO Section 2.2 Party Lamps

/* ID: lucien23 PROG: lamps LANG: C++ */ /* * 此题的技巧之处就是需要注意到任何button只要按下2的倍数次就相当于没有按 * 所以其实只需要考虑4个按钮,每个按钮是否被有效按下过一次就好 * 直接使用枚举法,一共只有2^4=16种情况 * 对于每种情况需要知道被按下的有效次数(也就是被按下过的按钮数),必须满足 * (C-有效次数)%2=0

程序缘 1222

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

USACO Training Section 2.2 Party Lamps

[url="http://ace.delos.com/usacoprob2?a=3nbwNTZTBNm&S=lamps"]英文原题[/url] [url="http://www.wzoi.org/usaco/13%5C104.asp"]中文题译[/url] 题目大意: 一组灯,几个按钮,按一个按钮可以改变若干灯的开关状态。给定按按钮的计数次数和最终状态中若干个灯的状态,要求求出所有可能状...

山中竹笋 176

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

USACO Section 2.2 Party Lamps(dfs)

Party LampsIOI 98 To brighten up the gala dinner of the IOI'98 we have a set ofN(10 <= N <= 100) colored lamps numbered from 1 toN. The lamps are connected to four buttons: Butto...

angtongyou1893的博客 179

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

USACO SECTION 2.2 Party Lamps

Party Lamps IOI 98 To brighten up the gala dinner of the IOI'98 we have a set of N (10 N. The lamps are connected to four buttons: Button 1: When this button is pressed, all the lamps chang

316

USACO-Section 2.2 Party Lamps (枚举)

灯长度是6个一循环,因为按钮1:每1个灯改变1个;按钮2:每2个灯改变1个;按钮3:每2个灯改变1个;按钮4:每3个灯改变1个,最小公倍数为6 ①易得任意一个按钮按下2次,等于该按钮按下0次 打表后观察得:②1,2,3这个3个按钮任意两个按下等同于第三个按下 由①得:任意偶数次按按钮均可以转化为0,2,4次按不同按钮,任意奇数次按按钮均可以转化为1,3次按不同按钮 由②得:所按按钮均不同时,相邻次数可以转化,即(1,2),(2,3),(3,4)这三种按不同按钮次数的组合内可以相互转化 综上:当按按钮次数大于

idealism_xxm的专栏 723

USACO-Section2.2 Party Lamps

USACO-Section2.2 Party Lamps

qq_34600424的博客 265

USACO - Chapter2 Section 2.2 - Party Lamps

Party Lamps

zhuo1ang的博客 311

USACO Section 2.2 Party Lamps - 看清本质就简单!

这题乍一看吓一跳...范围挺大的...想了也有一个小时才想通...看清本质!!     总共就4个按钮...如果我1,2,3,4都按过一次了..再按一下1 or 2 or 3 or 4灯的情况不和只按了2,3,4 or 1,3,4 or 1,2,4 or  1,2,3一样吗?因为一个按钮按两次就相当于没按..那么实际上能出现的最多情况也就是C(1,4)+C(2,4)+C(3,4)+C(4,4)=

zzyzzy12 1150

USACO-Section2.2 Party Lamps [枚举]

题目大意 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码。 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄灭,本来是关着的灯被点亮。 按钮2:当按下此按钮,将改变所有奇数号的灯。 按钮3:当按下此按钮,将改变所有偶数号的灯。 按钮4:当按下此按钮,将改变所有序号是3*K+1(K>=0)的灯

yoer77的博客 419

USACO section2.2 Party Lamps题解&思路

按两次灯就相当于没按…那么四个按钮就都分别只有两种状态:被按了和没有被按 枚举2^4种情况,如果这些情况需要的按键次数小于等于题目所给的次数且剩余按键次数是2的整数倍,那么这是一种符合要求的操作…然后暴力地比较所有需要比较的位数… 为什么这道题没有代码呢… 因为我发现这道题的操作是有每6位一循环的特点的…然后作死用了位运算…代码太感人…

Rainbow6174's home 657

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

    lamps解题报告------------------------------------------------------------------------------------------------------------------------------------------------【题目】   N个灯,编号1~N。有4个开关,和C次改变某个开关状态的机会,试问最终...

weixin_30828379的博客 140

USACO-Section2.2 Party Lamps【深度优先搜索】

题目描述:在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码。 这些灯都连接到四个按钮: 按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄灭,本来是关着的灯被点亮。 按钮2:当按下此按钮,将改变所有奇数号的灯。 按钮3:当按下此按钮,将改变所有偶数号的灯。 按钮4:当按下此按钮,将改变所有序号是3*K+1(K>=0)的灯。例如:1,4,7…

tjj1998的博客 345
上一篇: USACO section 2.2 Runaround Numbers
下一篇: 林大陈宇老师的原创高斯
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值