absi2011's Blog & Daily Life.

全新的开始       我要省选翻盘       I wanna AK in 高考\化学       自此,生无可恋
[破碎的状态] RQNOJ 707 [NOIP2012] 开车旅行
[破碎的状态] Codeforces 893F

[破碎的状态] 主代码手的练习(北京赛区D)(hihoCoder 1630)

absi2011 posted @ Nov 23, 2017 05:59:37 PM in 刷题记录 with tags 模拟 小高考 瞎搞 , 192 阅读

来源:北京赛区

http://hihocoder.com/problemset/problem/1630

一个纯代码题....

下次争取少WA几次....

注意...读题..........

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int player[6][15];
int board[25][35];
int belong_to[25][35];
int start[6][2]={
{0,12},
{16,12},
{9,3},
{7,21},
{9,21},
{7,3}};
void init()
{
    int i;
    for (i=0;i<25;i++)
    {
        int j;
        for (j=0;j<35;j++)
        {
            board[i][j]=-1;
            belong_to[i][j]=-1;
        }
    }
    for (i=4;i<=8;i++)
    {
        int j;
        for (j=12-i;j<=12+i;j+=2)
        {
            board[i][j]=-2;
        }
    }
    for (i=9;i<=12;i++)
    {
        int j;
        for (j=i-4;j<=28-i;j+=2)
        {
            board[i][j]=-2;
        }
    }
    for (i=0;i<6;i++)
    {
        if (i%2==0)
        {
            int j;
            for (j=0;j<4;j++)
            {
                int k;
                for (k=-j;k<=j;k+=2)
                {
                    board[start[i][0]+j][start[i][1]+k]=i;
                    belong_to[start[i][0]+j][start[i][1]+k]=i;
                }
            }
        }
        else
        {
            int j;
            for (j=0;j<4;j++)
            {
                int k;
                for (k=-j;k<=j;k+=2)
                {
                    board[start[i][0]-j][start[i][1]+k]=i;
                    belong_to[start[i][0]-j][start[i][1]+k]=i;
                }
            }
        }
    }
}
void print_screen()
{
    #ifndef absi2011
    return;
    #endif
    int i;
    for (i=0;i<=16;i++)
    {
        int j;
        for (j=0;j<=24;j++)
        {
            if (board[i][j]==-1)
            {
                printf(" ");
            }
            else if (board[i][j]==-2)
            {
                printf(".");
            }
            else
            {
                printf("%d",board[i][j]+1);
            }
        }
        printf("\n");
    }
    printf("\n\n");
}
int ansx,ansy;
void trans_to(int x,int y)
{
    if (x<=4)
    {
        ansx=x-1;
        ansy=y*2+11-x;
    }
    else if ((5<=x)&&(x<=9))
    {
        ansx=x-1;
        ansy=y*2+x-7;
    }
    else if ((10<=x)&&(x<=13))
    {
        ansx=x-1;
        ansy=y*2+11-x;
    }
    else
    {
        ansx=x-1;
        ansy=y*2+x-7;
    }
}
void trans_from(int x,int y)
{
    x++;
    ansx=x;
    if (x<=4)
    {
        ansy=(y+x-11)/2;
    }
    else if ((5<=x)&&(x<=9))
    {
        ansy=(y+7-x)/2;
    }
    else if ((10<=x)&&(x<=13))
    {
        ansy=(y+x-11)/2;
    }
    else
    {
        ansy=(y+7-x)/2;
    }
}
map<string,int> m;
int di[6][2]={
{0,2},
{0,-2},
{1,1},
{1,-1},
{-1,1},
{-1,-1}};
void moves(int x,int y,int z)
{
    int t1=0;
    int t2=0;
    int i;
    int nowx=x;
    int nowy=y;
    int best_movex=x;
    int best_movey=y;
    for (i=0;;i++)
    {
        nowx+=di[z][0];
        nowy+=di[z][1];
        if ((nowx<0)||(nowy<0)||(nowx>=17)||(nowy>=25)) break;
        if (board[nowx][nowy]==-1) break;
        if (board[nowx][nowy]!=-2)
        {
            t1<<=1;
            t1++;
            t2+=1<<i;
        }
        else if (((belong_to[nowx][nowy]^board[x][y])<=1)||(belong_to[nowx][nowy]==-1))
        {
            if (((t1==t2)&&(t1!=0))||(i==0))
            {
                best_movex=nowx;
                best_movey=nowy;
            }
            t1<<=1;
        }
        else
        {
            break;
        }
    }
    #ifdef absi2011
    printf("Move : %d %d To %d %d!\n",x,y,best_movex,best_movey);
    #endif
    swap(board[x][y],board[best_movex][best_movey]);
}
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    m["R"]=0;
    m["L"]=1;
    m["LR"]=2;
    m["LL"]=3;
    m["UR"]=4;
    m["UL"]=5;
    int n;
    for (;scanf("%d",&n)!=-1;)
    {
        init();
        print_screen();
        string t;
        static char c[5];
        int i;
        for (i=0;i<n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            trans_to(x,y);
            scanf("%s",c);
            t=c;
            #ifdef absi2011
            printf("%d %d %d\n",ansx,ansy,m[t]);
            #endif
            if (board[ansx][ansy]!=i%6) continue;
            moves(ansx,ansy,m[t]);
            print_screen();
        }
        for (i=0;i<6;i++)
        {
            int j,k;
            int cnt=0;
            for (j=0;j<25;j++)
            {
                for (k=0;k<35;k++)
                {
                    if (board[j][k]==i)
                    {
                        trans_from(j,k);
                        cnt++;
                        printf("%d %d",ansx,ansy);
                        if (cnt!=10) printf(" ");
                    }
                }
            }
            printf("\n");
        }
    }
    return 0;
}

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter