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

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 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. 【我的思路】 可以把这题分成两步,如果 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.


赞助商链接
相关文章:
面包和SUV
Rear and 车灯 turn signal lamps. √ 1 √ √ 70KW/3600rpm 10L/100KM Two front door, one side door and one back door 两个前门,一个 侧门和一个...
2015-2016学年陕西省西北大学附属中学高一下学期期中考试英语试题...
A. It will have pink lamps. B. It will have light green walls. C. It will have dark blue carpets on the floor. 听第 8 段材料,回答第 10 至 ...
Induction Lamps vs. HPS, Metal Halide & LED
1% 195W/40.6% 10% 200W低频无极灯 低频无极灯 200 20 220 80 16,000 80% 12,800 85 1.69 21,630 5,000 +19% 260W/54.2% 5% Induction Lamps vs...
LED Lamps Quotation
LED Lamps Quotation_机械/仪表_工程科技_专业资料 暂无评价|0人阅读|0次下载|举报文档 LED Lamps Quotation_机械/仪表_工程科技_专业资料。中山市好的科技有限...
Lamps and lanterns
Lamps and lanterns, mutatis mutandis, the location of the installed base hole pencil good hole, hole type nylon embolism, loading embolism (such as ...
惠州-eNodeB-4月-华为LAMPSIT站点作为吸收热点话务而引入时因支持...
案例:华为 LAMPSIT 站点作为吸收热点话务而引入时因支持频段不同的 RRU 混用组网导致强干扰问题研究 厂家 问题 类型 上报 省份 华为 问题编号 LAMPSIT 场景下异频...
Global LED Panel Lamps (LED面板灯) Market Research Report ...
Global LED Panel Lamps (LED面板灯) Market Research Report 2017 目录_电子/电路_工程科技_专业资料。Global LED Panel Lamps Market Research Report 2017 Pages...
...natural gas to light street lamps _答案_百度高考
The first recorded use of natural gas to light street lamps it was in the town of Frederick, New York, in 1825. A.wasB.isC.it isD.were_答案解析...
LED基础你知道多少
E17 两针 MR16 OR GU5.3 Mirror Reflector 16 x 1/8 吋直徑 GU10 3725000 3725001 Electric lamps 电灯泡(管) Lamps, arc, carbon 灯泡/灯管,碳弧式, (...
People in that district ______ use oil lamps, for t...
People in that district ______ use oil lamps, for there is no gas or electricity. A.canB.mayC.mustD.have to_答案解析_2016年_一模/二模/三模/...
更多相关标签: