2018年全國多校演算法寒假訓練營練習比賽(第一場)C 六子沖

來源:互聯網
上載者:User

標籤:div   blog   end   ==   多校   names   bre   pos   ems   

思路:

類比。

代碼:

#include<bits/stdc++.h>using namespace std;#define ll long long#define pb push_back#define mem(a,b) memset(a,b,sizeof(a))int dir[4][2]={-1,0,1,0,0,-1,0,1};int mp[5][5];int belong[15];int inx,iny;bool is(int x,int y,int xx,int yy){    if(x==inx&&y==iny)return true;    if(xx==inx&&yy==iny)return true;    return false;}int main(){    ios::sync_with_stdio(false);    cin.tie(0);    int cs=0,n,q,p;    while(cin>>n){        for(int i=1;i<=4;i++){            for(int j=1;j<=4;j++)mp[i][j]=0;        }        mp[1][1]=11;mp[1][2]=10;mp[1][3]=9;mp[1][4]=8;        mp[2][1]=12;                       mp[2][4]=7;        mp[3][1]=1;                        mp[3][4]=6;        mp[4][1]=2;mp[4][2]=3;mp[4][3]=4;mp[4][4]=5;        for(int i=1;i<=6;i++)belong[i]=1;        for(int i=7;i<=12;i++)belong[i]=2;        while(n--){            cin>>q>>p;            for(int i=1;i<=4;i++){                bool f=false;                for(int j=1;j<=4;j++){                    if(mp[i][j]==q){                        mp[i][j]=0;                        f=true;                        inx=i+dir[p-1][0];                        iny=j+dir[p-1][1];                        //cout<<inx<<" "<<iny<<endl;                        mp[inx][iny]=q;                        break;                    }                }                if(f)break;            }            for(int i=1;i<=4;i++){                if(is(i,1,i,2)&&mp[i][1]>0&&belong[mp[i][1]]==belong[mp[i][2]]&&belong[mp[i][2]]!=belong[mp[i][3]]&&mp[i][4]==0)mp[i][3]=0;                if(is(i,2,i,3)&&mp[i][2]>0&&belong[mp[i][2]]==belong[mp[i][3]]&&belong[mp[i][3]]!=belong[mp[i][4]]&&mp[i][1]==0)mp[i][4]=0;                if(is(i,2,i,3)&&mp[i][2]>0&&belong[mp[i][2]]==belong[mp[i][3]]&&belong[mp[i][2]]!=belong[mp[i][1]]&&mp[i][4]==0)mp[i][1]=0;                if(is(i,4,i,3)&&mp[i][3]>0&&belong[mp[i][3]]==belong[mp[i][4]]&&belong[mp[i][3]]!=belong[mp[i][2]]&&mp[i][1]==0)mp[i][2]=0;            }            for(int i=1;i<=4;i++){                if(is(1,i,2,i)&&mp[1][i]>0&&belong[mp[1][i]]==belong[mp[2][i]]&&belong[mp[2][i]]!=belong[mp[3][i]]&&mp[4][i]==0)mp[3][i]=0;                if(is(2,i,3,i)&&mp[2][i]>0&&belong[mp[2][i]]==belong[mp[3][i]]&&belong[mp[3][i]]!=belong[mp[4][i]]&&mp[1][i]==0)mp[4][i]=0;                if(is(2,i,3,i)&&mp[2][i]>0&&belong[mp[2][i]]==belong[mp[3][i]]&&belong[mp[2][i]]!=belong[mp[1][i]]&&mp[4][i]==0)mp[1][i]=0;                if(is(4,i,3,i)&&mp[3][i]>0&&belong[mp[3][i]]==belong[mp[4][i]]&&belong[mp[3][i]]!=belong[mp[2][i]]&&mp[1][i]==0)mp[2][i]=0;            }            /*for(int i=1;i<=4;i++){            for(int j=1;j<=4;j++){                cout<<setw(3)<<mp[i][j];            }            cout<<endl;        }*/        }        cout<<"#Case "<<++cs<<":"<<endl;        for(int i=1;i<=4;i++){            for(int j=1;j<=4;j++){                cout<<setw(3)<<mp[i][j];            }            cout<<endl;        }    }    return 0;}

 

2018年全國多校演算法寒假訓練營練習比賽(第一場)C 六子沖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.