zoukankan      html  css  js  c++  java
  • 1.4.2 The Clocks

    The Clocks
    IOI'94 - Day 2

    Consider nine clocks arranged in a 3x3 array thusly:

    |-------|    |-------|    |-------|    
    |       |    |       |    |   |   |    
    |---O   |    |---O   |    |   O   |          
    |       |    |       |    |       |           
    |-------|    |-------|    |-------|    
        A            B            C
    
    |-------|    |-------|    |-------|
    |       |    |       |    |       |
    |   O   |    |   O   |    |   O   |
    |   |   |    |   |   |    |   |   |
    |-------|    |-------|    |-------|
        D            E            F
    
    |-------|    |-------|    |-------|
    |       |    |       |    |       |
    |   O   |    |   O---|    |   O   |
    |   |   |    |       |    |   |   |
    |-------|    |-------|    |-------|
        G            H            I
    

    The goal is to find a minimal sequence of moves to return all the dials to 12 o'clock. Nine different ways to turn the dials on the clocks are supplied via a table below; each way is called a move. Select for each move a number 1 through 9 which will cause the dials of the affected clocks (see next table) to be turned 90 degrees clockwise.

    Move Affected clocks
    1 ABDE
    2 ABC
    3 BCEF
    4 ADG
    5 BDEFH
    6 CFI
    7 DEGH
    8 GHI
    9 EFHI

    Example

    Each number represents a time accoring to following table:

    9 9 12       9 12 12       9 12 12        12 12 12      12 12 12 
    6 6 6  5 ->  9  9  9  8->  9  9  9  4 ->  12  9  9  9-> 12 12 12 
    6 3 6        6  6  6       9  9  9        12  9  9      12 12 12 
    

    [But this might or might not be the `correct' answer; see below.]

    PROGRAM NAME: clocks

    INPUT FORMAT

    Lines 1-3: Three lines of three space-separated numbers; each number represents the start time of one clock, 3, 6, 9, or 12. The ordering of the numbers corresponds to the first example above.

    SAMPLE INPUT (file clocks.in)

    9 9 12
    6 6 6
    6 3 6
    

    OUTPUT FORMAT

    A single line that contains a space separated list of the shortest sequence of moves (designated by numbers) which returns all the clocks to 12:00. If there is more than one solution, print the one which gives the lowest number when the moves are concatenated (e.g., 5 2 4 6 < 9 3 1 1).

    SAMPLE OUTPUT (file clocks.out)

    4 5 8 9
    

    {
    ID:makeeca1
    PROG:clocks
    LANG:PASCAL
    }
    const ch:array[1..9,1..9]of 0..3=
                  ((3,3,3,3,3,2,3,2,0),
                   (2,3,2,3,2,3,1,0,1),
                   (3,3,3,2,3,3,0,2,3),
                   (2,3,1,3,2,0,2,3,1),
                   (2,3,2,3,1,3,2,3,2),
                   (1,3,2,0,2,3,1,3,2),
                   (3,2,0,3,3,2,3,3,3),
                   (1,0,1,3,2,3,2,3,2),
                   (0,2,3,2,3,3,3,3,3));
    var a:array[1..9]of byte;
         ans:array[1..9]of byte;
         i,j,k:byte;
         s:string;
    begin
    assign(input,'clocks.in');
    reset(input);
    assign(output,'clocks.out');
    rewrite(output);
       readln(a[1],a[2],a[3]);
       readln(a[4],a[5],a[6]);
       readln(a[7],a[8],a[9]);
       for i:=1 to 9 do
         a[i]:=a[i] div 3;
       for i:=1 to 9 do
         for k:=1 to 9 do
           inc(ans[k],ch[i,k]*(4-a[i]));
       for i:=1 to 9 do
         ans[i]:=ans[i] and 3;
       s:='';
       for i:=1 to 9 do
         for j:=1 to ans[i] do
           s:=s+chr(i+48)+' ';
       delete(s,length(s),1);
       writeln(s);
    close(input);
    close(output);
    end.
  • 相关阅读:
    pl/sql developer中如何导出oracle数据库结构? 参考文章一
    ORACLE知识点整理之一
    WebService之第一天
    Eclipse中,open declaration;open implementation;open super implementation的区别
    Maven 手动添加 JAR 包到本地仓库
    clipse maven 项目 出现红色叹号 解决方法
    eclipse快捷键设置
    Hibernate3--快速入门--第一天
    C++ 虚函数表解析
    c++ primer复习(二)
  • 原文地址:https://www.cnblogs.com/makeecat/p/3274510.html
Copyright © 2011-2022 走看看