当前位置:首页 >> 学科竞赛 >>

lamps


【题目描述】

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 connecte

d 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. 【我的思路】 可以把这题分成两步,如果 C 是个奇数的话,就相当于每个按键都可能按一下,如果 C 是 个偶数的话,相当于任意两个不同的按钮被按了,然后就把每种情况列举一下。要注意的是 它 IMPOSSIBLE 的判断。 【code】 { ID:yxy07015 PROG:lamps LANG:PASCAL } var n,c,m,x,i:integer; shine,b:array[1..103] of integer; possible:boolean; procedure print; begin for i:=1 to n-1 do write(shine[i]); writeln(shine[n]); end; function check:boolean; begin for i:=1 to n do if b[i]<>0 then

begin if (b[i]=1) and (shine[i]=0) then exit(false); if (b[i]=-1) and (shine[i]=1) then exit(false); end; exit(true); end; procedure doit2; begin for i:=1 to n do shine[i]:=1; for i:=1 to n do shine[i]:=(shine[i]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; for i:=0 to n div 3 do shine[i*3+1]:=(shine[i*3+1]+1) mod 2; for i:=1 to m do shine[i*2]:=(shine[i*2]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; for i:=1 to m+1 do shine[i*2-1]:=(shine[i*2-1]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; for i:=0 to n div 3 do shine[i*3+1]:=(shine[i*3+1]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; for i:=1 to n do shine[i]:=(shine[i]+1) mod 2; for i:=0 to n div 3 do shine[i*3+1]:=(shine[i*3+1]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; for i:=1 to m do shine[i*2]:=(shine[i*2]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; for i:=1 to m+1 do shine[i*2-1]:=(shine[i*2-1]+1) mod 2; for i:=0 to n div 3 do shine[i*3+1]:=(shine[i*3+1]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; if check then begin print; possible:=true; end; end; procedure doit1; begin for i:=1 to n do shine[i]:=1; for i:=1 to n do shine[i]:=(shine[i]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; for i:=1 to m+1 do shine[i*2-1]:=(shine[i*2-1]+1) mod 2;

if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; for i:=0 to n div 3 do shine[i*3+1]:=(shine[i*3+1]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; for i:=1 to m do shine[i*2]:=(shine[i*2]+1) mod 2; if check then begin print; possible:=true; end; for i:=1 to n do shine[i]:=1; if check then begin print; possible:=true; end; end; begin assign(input,'lamps.in'); reset(input); assign(output,'lamps.out'); rewrite(output); readln(n); readln(c); fillchar(b,sizeof(b),0); read(x); possible:=true; while x<>-1 do begin inc(b[x]); read(x); possible:=false; end; read(x); while x<>-1 do begin dec(b[x]); read(x); possible:=false; end; if (c=0) and possible then begin for i:=1 to n-1 do write(1); writeln(1); exit; end else if (c=0) and not possible then begin writeln('IMPOSSIBLE'); exit; end; m:=n div 2; possible:=false; if c mod 2=1 then doit1 else doit2; if not possible then writeln('IMPOSSIBLE'); close(input); close(output); end.

Executing... Test 1: TEST OK [0.000 secs, 280 KB] Test 2: TEST OK [0.000 secs, 280 KB] Test 3: TEST OK [0.000 secs, 280 KB] Test 4: TEST OK [0.000 secs, 280 KB] Test 5: TEST OK [0.003 secs, 280 KB] Test 6: TEST OK [0.000 secs, 280 KB] Test 7: TEST OK [0.000 secs, 280 KB] Test 8: TEST OK [0.003 secs, 280 KB] All tests OK.


相关文章:
lamp是什么
lamp是什么_文学_高等教育_教育专区。计算机的一种体系结构lamp 是什么 目前 lamp 的应用已经非常广泛,lamp 是基于 Linux,Apache,MySQL 和 PHP 的开放资源网络开...
使用yum安装LAMP的方法
使用yum 安装 LAMP 的方法 使用 yum 安装 LAMP 的方法: 1、yum update 检查一下系统更新 初次安装可能更新的时间会比较长,请耐心等待。 2、yum install gcc ...
LAMP设置文档
LAMP设置文档_教学研究_教育专区。linux+apache+mysql+php搭建的linux系统的lamp架构,个人在制作,很详细 Linux+apache +mysql +php 设置文档一. 配置 mysql 1. ...
LAMP服务器搭建
LAMP服务器搭建_IT/计算机_专业资料。LAMP 服务器搭建 玩 php 也一年多了,linu 也早在一年前就接触了,但后来转到 Windows 上开发,lamp,也就 生疏很多了。...
灯饰中英文术语
灯饰中英文术语_电子/电路_工程科技_专业资料。灯饰英语一、 室内灯 Residential lamp / light chandeliers pendant lamp / light half pendant lamp / light tab...
LAMP网站服务搭建
Linux 系列-Red Hat5 平台下的 LAMP 网站服务搭建(一 2010-02-25 23:45:46 标签:Linux Red Hat LAMP [推送到技术圈] Linux 系列-Red Hat5 平台下的 ...
无单点故障高性能LAMP集群的构建_图文
无单点故障高性能 LAMP 集群的构建 无单点故障高性能 LAMP 集群的构建 摘要 随着计算机技术的泛的应用,人们对其的依赖程度越来越高,计算机的可靠 性和可用性便...
骐达11款保险丝翻译
POS LAMPS R 右前后示宽灯 10A F7:POS LAMPS L 左前后示宽灯 10A F9:A/C CLUTCH 空调离合器 10A F10:FR FOG LAMP 前雾灯 15A F11:H/LAMP HI RH ...
linux上的Apache服务和LAMP环境的配置详细步骤
LAMP 说的是 linux 操作系统作为 web 服务体系的构建平台,Apache 服务体系的构建平台, 服务器, 数据库服务器, 作为前端的 web 服务器,Mysql 作为后端的 SQL ...
Linux下LAMP的搭建
Linux 下 LAMP 的搭建 Linux+Apache+Mysql+PHP,一组常用来搭建动态网站或者服务器的开源软本身都是 各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的...
更多相关标签: