【題解】洛谷1618 三連擊(升…

本題地址: http://www.luogu.org/problem/show?pid=1618

題目描述

將1,2,…,9共9個數分成三組,分別組成三個三位數,且使這三個三位數的比例是A:B:C,試求出所有滿足條件的三個三位數,若無解,輸出“No!!!”。 

//感謝黃小U飲品完善題意

輸入輸出格式

輸入格式:

三個數,A B C。

輸出格式:

若干行,每行3個數字。按照每行第一個數字升序排列。

輸入輸出樣例

輸入樣例#1:

1 2 3
輸出樣例#1:

192 384 576
219 438 657
273 546 819
327 654 981

說明

保證A

默默打表,多重判斷,因爲數據就這麼弱
var a,b,c,i,j,k,t:longint;
 n:array[0..100000]of longint;
 f:array[1..9]of boolean;
 p:boolean;
function exi(a,b,c:longint):boolean;
 var i:longint;s1,s2,s3:string;
 begin
  str(a,s1);
  str(b,s2);
  str(c,s3);
  for i:=1 to 3 do
   begin
    if pos(s1[i],s2)>0 then exit(false);
    if pos(s2[i],s1)>0 then exit(false);
    if pos(s1[i],s3)>0 then exit(false);
    if pos(s3[i],s1)>0 then exit(false);
    if pos(s2[i],s3)>0 then exit(false);
    if pos(s3[i],s2)>0 then exit(false);
   end;
  exi:=true;
 end;
begin
fillchar(f,sizeof(f),true);
p:=false;
for i:=1 to 9 do
 begin
  f[i]:=false;
  for j:=1 to 9 do
   if f[j] then
    begin
     f[j]:=false;
     for k:=1 to 9 do
      if f[k] then
       begin
        inc(t);
        n[t]:=i*100+j*10+k;
       end;
     f[j]:=true;
    end;
  f[i]:=true;
 end;
readln(a,b,c);
for i:=1 to t-2 do
 for j:=i+1 to t-1 do
  for k:=i+2 to t do
   if (a*n[j]=b*n[i])and(a*n[k]=c*n[i])and(b*n[k]=c*n[j])and exi(n[i],n[j],n[k])
    then
     begin
      p:=true;
      writeln(n[i],' ',n[j],' ',n[k]);
     end;
if not(p) then
 writeln('No!!!');
end.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章