USACO section 2.2 Party Lamps

Python爬虫实战:基于最新技术栈的晋江文学城小说爬取 本文将详细介绍如何使用Python最新技术栈构建一个高效的晋江文学城小说爬虫。我们将从爬虫基础知识讲起,逐步深入到反爬机制应对、分布式爬虫设计以及数据存储优化等高级话题。文章包含完整的代码实现,使用aiohttp+asyncio实现异步爬取,Playwright处理动态渲染,并结合Redis实现分布式任务队列。本文旨在为读者提供一个全面的现代Python爬虫开发指南。网络爬虫(Web Crawler)是一种自动抓取互联网信息的程序,广泛应用于搜索引擎、数据分析和内容聚合等领域。 阅读详情
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);
}

 

 

 

实战|2026美团&大众点评餐饮数据抓取:Playwright/Selenium反爬全攻略 核心结论:2026年美团&大众点评的反爬核心是“多维度风控”,需组合使用“住宅IP+设备指纹伪装+真人行为模拟+动态验证处理”,Playwright是最优工具,Selenium仅作为补充。效率优化:单机爬取速度建议控制在“每小时500-800条”,避免高频请求触发风控;分布式爬取需确保每个节点使用独立住宅IP,且行为轨迹不一致。扩展方向集成WASM解密工具,破解2026年美团的Token加密;用AI识别动态点选验证,提升验证通过率;对接大数据平台,对抓取的餐饮数据进行可视化分析。 阅读详情

相关推荐

小程序 video 控制器外观调整_Kessil 360X Tuna Sun无线控制器使用分享

之前分享了Kessil 360X Tuna Sun开箱记录,时间关系,没来得及使用WiFi Dongle无线控制器。昨晚抽空实操了一下,做个操作记录,希望对大家有参考Kessil无线模块操作指南官方视频英文教程配中文字幕,非常详尽语速较快,重点位置可以暂停操作点击边框调出视频工具条1、拆包取控制器,保存二维码Kessil WiFi Dongle包装打开包装就能看到Kessil无线控制模...

weixin_39759060的博客 4733

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

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

杨子曰:代码是神奇的 797

[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

代码详解——Transformer

对于一个序列,在 time_step 为 t 的时刻,我们的解码输出应该只能依赖于 t 时刻之前的输出,而不能依赖 t 之后的输出。当 Decoder 的输入矩阵和 Mask 矩阵输入矩阵包含 “ I have a cat” (0, 1, 2, 3, 4) 五个单词的表示向量,Mask 是一个 5×5 的矩阵。然后判断是否传入的mask, 如果有mask (mask参数值不为None),则把mask为0的位置,将对应位置的attn的值设为无穷小的负数。可以发现得到的输出和输入的K,Q,V的大小相同。

zyw2002的博客 7213

AI全景之第八章第三节:时间序列分析与预测技术

摘要 时间序列分析与预测技术从传统统计模型发展到深度学习方法。传统方法包括ARIMA模型(处理趋势和季节性)、指数平滑(加权平均预测)和状态空间模型(概率框架分解)。机器学习方法通过特征工程和树模型提升非线性建模能力。深度学习方法中,RNN/LSTM处理序列依赖,TCN利用因果卷积,Transformer通过注意力机制捕获长程依赖。当前研究趋势结合神经符号方法和生成模型,以提高预测精度和可解释性。不同方法各具优势,需根据数据特性和预测需求选择。

技术引领业务创新 989

派对灯(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

超酷炫,Python实现交通数据可视化!

此时输出的栅格化参数params的内容存储了栅格坐标系的原点坐标(slon、slat)、单个栅格的经纬度长宽 (deltalon、deltalat)、栅格的旋转角度(theta)、栅格的形状(method参数,其值可以是方形rect、三角形tri和六边形hexa)以及栅格的大小(gridsize参数,单位为米)。Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。今天分享一次Python交通数据分析与可视化的实战!

m0_59236127的博客 1697

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

图像传感器与信号处理——详解CCD与CMOS图像传感器

一文详解CCD与CMOS图像传感器一文详解CCD与CMOS图像传感器1. 图像传感器性能关键词1.1 噪声1.2 暗电流 一文详解CCD与CMOS图像传感器 本文主要总结了CCD与CMOS传感器的原理知识,参考书籍为《数码相机中图像传感器和信号处理》,英文版为《Image Sensors And Signal Processing for Digital Still Cameras》 1. 图像传...

weixin_44580210的博客 2万+

Unreal5 从入门到精通之 如何实现 离线语音识别

本文介绍了如何使用离线语音识别插件 Offline Speech Recognition 进行本地语音转文本处理。该插件支持离线运行,用户可以通过下载并运行语言服务器(如 Vosk)来处理语音数据。文章详细说明了如何设置语言服务器、下载语言模型,并在虚幻引擎(UE)项目中配置麦克风和语音捕获。此外,还介绍了如何将 SoundWave 作为输入,以及如何通过节点将语音数据发送到语言服务器进行处理。最后,提供了相关文档链接以供进一步参考。

TxNet 905

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

大疆司空 2 私有化部署:FH2、Terra、4G 三大服务区别详解

摘要: 司空2私有版包含三大模块:FH2(核心平台,必选)、Terra(建模算力,需NVIDIA显卡)、4G(内网图传)。FH2是基础,支持设备管理与任务调度;Terra适用于测绘建模场景,依赖GPU算力;4G模块保障复杂环境下的图传稳定性,适合纯内网部署。选择逻辑:先部署FH2,再按需添加Terra(需显卡)或4G(需内网支持),避免资源浪费。

2501_93651177的博客 579

USACO Section 2.2 Party Lamps

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

程序缘 1222

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

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

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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、付费专栏及课程。

余额充值