【習題 7-6 UVA - 12113】Overlapping Squares

來源:互聯網
上載者:User

標籤:pen   source   輸入   span   gpo   least   回溯   座標   ret   

【連結】 我是連結,點我呀:)
【題意】


在這裡輸入題意

【題解】


先預先處理出來一個正方形。
然後每次枚舉新加的正方形左上方的座標就可以。
注意覆蓋的規則,控制一下就可以。
然後暴力判斷是否相同。
暴力回溯即可(只用回溯一個正方形地區)

【代碼】

/*    1.Shoud it use long long ?    2.Have you ever test several sample(at least therr) yourself?    3.Can you promise that the solution is right? At least,the main ideal    4.use the puts("") or putchar() or printf and such things?    5.init the used array or any value?    6.use error MAX_VALUE?    7.use scanf instead of cin/cout?    8.whatch out the detail input require*//*    一定在這裡寫完思路再敲代碼!!!*/#include <bits/stdc++.h>using namespace std;const int N = 10;const int M = 5;char s[N+5][N+5],now[N+5][N+5];char square[M+5][M+5];void init(){    for (int i = 0;i <3;i++)        for (int j = 0;j<5;j++)            square[i][j] = ' ';    for (int i = 0;i < 2;i++) square[i+1][0] = square[i+1][4] = '|';    for (int j = 1;j < 5;j+=2) square[0][j]=square[2][j] = '_';}void Set(int x,int y){    for (int i = 0;i < 3;i++)        for (int j = 0;j < 5;j++){            if (i<=0 && now[i+x][j+y]!=' ' && square[i][j]==' ') continue;            now[i+x][j+y] = square[i][j];        }    for (int i = 1;i < 2;i++)        for (int j = 1;j<4;j++)            now[i+x][j+y] = ' ';}bool ok(){    for (int i = 0;i < 5;i++)        for (int j = 0;j < 9;j++)            if (now[i][j]!=s[i][j])                return false;    return true;}void out(){    for (int i = 0;i < 5;i++){        for (int j = 0;j < 9;j++)            cout <<now[i][j];        cout << endl;    }    cout << endl;}bool dfs(int dep){    if (dep > 1 && ok()) return true;    if (dep >= 7) return false;    int temp[M+5][M+5];    for (int i = 0;i < 3;i++){        for (int j = 0;j < 5;j+=2){            for (int k = 0;k <3;k++)                for (int l = 0;l < 5;l++)                    temp[k][l] = now[k+i][l+j];            Set(i,j);            if (dfs(dep+1)) return true;            for (int k = 0;k <3;k++)                for (int l = 0;l < 5;l++)                    now[k+i][l+j] = temp[k][l];        }    }    return false;}int main(){    #ifdef LOCAL_DEFINE        freopen("rush_in.txt", "r", stdin);    #endif    ios::sync_with_stdio(0),cin.tie(0);    init();    int kase = 0;    while (1){        for (int i = 0;i < 5;i++){            cin.getline(s[i],15);            if (s[i][0]=='0') return 0;        }        for (int i = 0;i< 5;i++)            for (int j = 0;j < 9;j++)                now[i][j] = ' ';        if (dfs(1)){            cout <<"Case "<<++kase<<": Yes"<<endl;        }else{            cout <<"Case "<<++kase<<": No"<<endl;        }    }    return 0;}

【習題 7-6 UVA - 12113】Overlapping Squares

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.