usaco吧 关注:342贴子:1,254
  • 2回复贴,共1

USACO1.4.2 Clocks求助

只看楼主收藏回复

1L


IP属地:重庆1楼2013-02-23 16:58回复
    #include<iostream>
    #include<fstream>
    #include<cstdio>
    using namespace std;
    int Clock[10],path[50000000],ok=0,step=0;
    int change[][10]=
    {{0},
    {0,1,1,0,1,1,0,0,0,0},
    {0,1,1,1,0,0,0,0,0,0},
    {0,0,1,1,0,1,1,0,0,0},
    {0,1,0,0,1,0,0,1,0,0},
    {0,0,1,0,1,1,1,0,1,0},
    {0,0,0,1,0,0,1,0,0,1},
    {0,0,0,0,1,1,0,1,1,0},
    {0,0,0,0,0,0,0,1,1,1},
    {0,0,0,0,0,1,1,0,1,1}};
    int check()
    {
    for(int i=1;i<=9;i++)
    if(Clock[i]!=0)
    return 0;
    return 1;
    }
    void add(int *c,int x,int *ch)
    {
    for(int i=1;i<=9;i++){
    c[i]+=x*ch[i];
    c[i]%=4;
    }
    }
    void run(int i,int k)
    {
    if(check()){
    ok=1;
    step=k;
    return;
    }
    if(i>9)
    return;
    for(int x=0;x<=3;x++){
    if(!ok){
    if(x!=0){
    add(Clock,x,change[i]);
    path[k+x]=i;
    }
    run(i+1,k+x);
    }
    }
    }
    void out()
    {
    for(int i=1;i<=step;i++)
    cout<<path[i]<<" ";
    cout<<endl;
    }
    int main()
    {
    freopen("P1.in","r",stdin);
    freopen("P1.out","w",stdout);
    for(int i=1;i<=9;i++){
    cin>>Clock[i];
    Clock[i]/=3;
    Clock[i]%=4;
    }
    /*for(int i=1;i<=9;i++)
    cout<<Clock[i]<<" ";
    cout<<endl;*/
    run(1,0);
    out();
    return 0;
    }


    IP属地:重庆2楼2013-02-23 16:59
    回复
      求指点哪里错了,感谢~~


      IP属地:重庆3楼2013-02-23 16:59
      回复