USACO section 2.2 Party Lamps

MDT部署实战:除了Office,这些“装机必备”软件也能一键静默安装(含静默参数) 本文详细介绍了如何利用Microsoft Deployment Toolkit(MDT)实现企业级软件的静默安装,包括浏览器、开发工具和系统增强工具等“装机必备”软件的部署方案。通过命令行参数和MSI属性,IT运维团队可以高效构建标准化工作环境,提升部署效率并确保版本一致性。文章还提供了安装顺序控制、结果验证和常见问题排错等高级技巧。 阅读详情
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);
}

 

 

 

数值计算方法 matlab用二分法或简单迭代法求_快速求解方程的根——二分法与牛顿迭代法 今天是周四高等数学专题的第7篇文章。之前的文章和大家聊了许多数学上的理论,今天和大家聊点有用的东西。我们都知道,工业上的很多问题经过抽象和建模之后,本质还是数学问题。而说到数学问题就离不开方程,在数学上我们可以用各种推算、公式,但是有没有想过在计算机领域我们如何解一个比较复杂的方程?如果之前没有想过,那你可能得想一想,因为以后很有可能会在面试题当中遇到。二分法我们要介绍的第一个方法是二分法。说到二... 阅读详情

相关推荐

【前端HTML生成条形码——MQ】

本文将展示前端HTML如何根据用户输入内容生成对应的条形码,附HTML和JS代码。代码如下(示例):

weixin_42588676的博客 1962

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

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

杨子曰:代码是神奇的 798

Ubuntu环境下rknn-toolkit2的安装与兼容性解析

本文详细解析了在Ubuntu系统上安装瑞芯微rknn-toolkit2工具链的完整流程与关键注意事项。文章重点剖析了rknn-toolkit2与旧版rknn-toolkit的核心兼容性问题,强调两者在API、模型格式及运行时库上互不兼容,并推荐使用Conda虚拟环境进行隔离管理,为RK3566、RK3588等开发板的AI模型部署提供清晰的实践指南。

weixin_29041767的博客 384

[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的博客 477

自适应动态规划硕士博士论文学习

强化学习关注随机过程中的序贯决策问题,而自适应动态规划关注动态系统的控制问题。吸引域:系统渐近稳定的区域。

DarlingLSA的博客 1437

基于共识的捆绑算法CBBA在多无人机多任务调度中的实现

在捆绑过程中,每个无人机根据自己的任务清单和其他无人机的任务清单,确定一个被称为“束”的集合。通过合理的任务分配和无人机协作,CBBA算法能够实现最优的任务调度,提高了多无人机系统的效率和执行能力。在每一轮迭代中,无人机根据自己的当前任务和位置信息将任务清单发送给其他无人机,并接收其他无人机发送过来的任务清单。通过比较其他无人机的任务清单和自身的任务清单,每个无人机可以更新自己的任务分配情况。在这一步中,每个无人机根据自己选择的新任务,更新自身的任务清单,并将更新后的清单发送给其他无人机。

持续更新 1159

派对灯(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的博客 420

NVIDIA Isaac Sim 联合 VS Code 开发调试环境配置

在 Visual Studio Code (VS Code) 中打开 Isaac Sim 软件包主文件夹,即可打开该工作区。注意建议在学习教程和示例时使用 Visual Studio Code。另请参见有关 VS Code 工作区的详细信息,请参阅 Visual Studio Code (VS Code) 文档。

2506_90492529的博客 3115

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

098、C3k2_Ghost:用 GhostConv 替代 C3k2 内标准卷积的轻量化改造代码

本文介绍了用GhostConv轻量化改造YOLOv11中C3k2模块的实践。作者通过线上部署案例引出问题,详细解析了GhostConv的核心实现逻辑,指出直接替换标准卷积会导致的两个关键问题:通道数不匹配和kernel_size冲突。文章提供了完整的C3k2_Ghost实现代码,包含注意事项和调试技巧。消融实验显示,该方法在小模型上可减少27%-28%参数量、34%-35%FLOPs,仅损失0.8mAP。作者总结了适用场景:小模型效果显著,大模型需谨慎;检测小目标任务不推荐;训练时需调整学习率。最后强调sh

sundong_81的博客 64

国社科“选题设计论证”部分不再难!用AI快速梳理五大核心板块,轻松撰写出高质量的基金申报书(附AI提示词)

七哥给大家推荐的高校都在用的AI平台——高级学术版专业应用平台,集成了ChatGPT、Claude、Gemini、Grok等Al大模型的PLUS版本平台,包括 ChatGPT-5、4o、o3、4.1、4.5、Gemini 2.5 Pro、Claude 3.7、Claude 4、DeepSeek 满血版、Grok 3 、Grok 4等原生线路,还有国际主流的GPTs学术应用,可以辅助大家高效完成科研和学术写作任务,当然撰写硕博论文,课题、职称论文、国社科、国自然基金本子也是手拿把掐。

智能AI让学术科研更容易 940

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的博客 237

【Matlab】飞行器气动弹性仿真与分析

气动弹性是飞行器设计领域的核心交叉学科,融合了空气动力学、结构动力学和控制理论,主要研究飞行器结构在气动力作用下的弹性变形、振动响应及相互耦合规律,直接影响飞行器的飞行稳定性、操纵性和结构安全性。随着飞行器向高速度、高机动性、轻量化方向发展,气动弹性问题愈发突出,如颤振、发散、嗡鸣等现象,严重时会导致飞行器结构破坏甚至飞行事故,因此气动弹性仿真与分析已成为飞行器设计、验证和优化的关键环节。当前,飞行器气动弹性仿真面临诸多技术挑战:气动力与结构变形的强耦合特性难以精准描述,易出现仿真误差;

unber的博客 245

USACO Section 2.2 Party Lamps

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

程序缘 1222

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

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

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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的博客 180

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的专栏 725

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的博客 420

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的博客 141

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的博客 346
上一篇: 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、付费专栏及课程。

余额充值