穷举水题
1 var v:array[0..410] of boolean; 2 q:array[0..3010] of longint; 3 ans,count,jud:array[0..1010] of longint; 4 x,i,j,n,m,tot,t,k:longint; 5 6 function check:boolean; //贪心判断 7 var i:longint; 8 begin 9 for i:=1 to n+2 do 10 begin 11 if jud[i]<0 then exit(false); 12 jud[i]:=jud[i] mod 3; 13 if jud[i]>0 then 14 begin 15 dec(jud[i+1],jud[i]); 16 dec(jud[i+2],jud[i]); 17 jud[i]:=0; 18 end; 19 end; 20 exit(true); 21 end; 22 23 begin 24 readln(n,m); 25 for i:=1 to 3*m+1 do 26 begin 27 read(x); 28 if count[x]=0 then 29 begin 30 inc(t); 31 q[t]:=x; 32 end; 33 inc(count[x]); 34 v[x]:=true; 35 v[x-1]:=true; 36 v[x+1]:=true; 37 end; 38 39 for i:=1 to n do 40 if v[i] then //穷举添加的牌 41 begin 42 for j:=1 to n do 43 jud[j]:=count[j]; 44 inc(jud[i]); 45 for j:=1 to t do //穷举对子 46 begin 47 dec(jud[q[j]],2); 48 if check then 49 begin 50 inc(tot); 51 ans[tot]:=i; 52 break; 53 end; 54 for k:=1 to n+2 do 55 jud[k]:=count[k]; 56 inc(jud[i]); 57 end; 58 end; 59 60 if tot=0 then writeln('NO') 61 else begin 62 for i:=1 to tot do 63 begin 64 write(ans[i]); 65 if i<>tot then write(' '); 66 end; 67 writeln; 68 end; 69 end.