zoukankan      html  css  js  c++  java
  • hdu 3682 10 杭州 现场 C

    C - To Be an Dream Architect
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Appoint description: 

    Description

    The “dream architect” is the key role in a team of “dream extractors” who enter other’s dreams to steal secrets. A dream architect is responsible for crafting the virtual world that the team and the target will dream into. To avoid the target noticing the world is artificial, a dream architect must have powerful 3D imagination. 

    Cobb uses a simple 3D imagination game to test whether a candidate has the potential to be an dream architect. He lets the candidate imagine a cube consisting of n×n×n blocks in a 3D coordinate system as Figure 1. The block at bottom left front corner is marked (1, 1, 1) and the diagonally opposite block is marked (n, n, n). Then he tells the candidate that the blocks on a certain line are eliminated. The line is always parallel to an axis. After m such block eliminations, the candidate is asked to tell how many blocks are eliminated. Note that one block can only be eliminated once even if it is on multiple lines. 

    Here is a sample graph according to the first test case in the sample input: 
     

    Input

    The first line is the number of test cases. 
    In each test case, the first line contains two integers n and m( 1 <= n <= 1000, 0 <= m <= 1000).,meaning that the cube is n x n x n and there are m eliminations. 

    Each of the following m lines represents an elimination in the following format: 
    axis_1=a, axis_2=b 
    where axis_i (i=1, 2) is ‘X’ or ‘Y’, or ‘Z’ and axis_1 is not equal to axis_2. a and b are 32-bit signed integers. 
     

    Output

    For each test case output the number of eliminated blocks.
     

    Sample Input

    2 3 2 Y=1,Z=3 X=3,Y=1 10 2 X=3,Y=3 Y=3,Z=3
     

    Sample Output

    5 19
     
     思路:设z轴方向的消除为固定xy,x轴为yz,y轴为xz,那么就是要求出这三块的总计大小,容斥
    感想:数组名起的不好,写起来燃烧生命
     
    #include <cstdio>
    #include <cstring>
    using namespace std;
    int n,m;
    int a,b,c,d;
    bool xy[1001][1001],xz[1001][1001],yz[1001][1001];
    int xylen[1001],yxlen[1001],yzlen[1001],zxlen[1001],zylen[1001],xzlen[1001];
    char buff[100];
    int xzheap[1001][2];
    int read1(){
        int ans=0;
        for(int i=2;i<=6;i++){
            if(buff[i]>'9'||buff[i]<'0')break;
            ans*=10;
            ans+=buff[i]-'0';
        }
        return ans;
    }
    int read2(){
        int ans=0;
        int i=6;
        while(buff[i]>'9'||buff[i]<'0'){i++;}
        for(;;i++){
            if(buff[i]>'9'||buff[i]<'0')break;
            ans*=10;
            ans+=buff[i]-'0';
        }
        return ans;
    }
    void inset(char ch1,char ch2,int num1,int num2){
        if(ch1=='X'){
            if(ch2=='Y'){
                if(!xy[num1][num2]){
                    a++;
                    xy[num1][num2]=true;
                    xylen[num1]++;
                    yxlen[num2]++;
                }
            }
            if(ch2=='Z'){
                if(!xz[num1][num2]){
                    xzheap[b][0]=num1;
                    xzheap[b++][1]=num2;
                    xz[num1][num2]=true;
                    xzlen[num1]++;
                    zxlen[num2]++;
                }
            }
        }
        if(ch1=='Y'){
            if(ch2=='X'){
                if(!xy[num2][num1]){
                    a++;
                    xy[num2][num1]=true;
                    xylen[num2]++;
                    yxlen[num1]++;
                }
            }
            if(ch2=='Z'){
                if(!yz[num1][num2]){
                    c++;
                    yz[num1][num2]=true;
                    yzlen[num1]++;
                    zylen[num2]++;
                }
            }
        }
        if(ch1=='Z'){
            if(ch2=='X'){
                if(!xz[num2][num1]){
                    xzheap[b][0]=num2;
                    xzheap[b++][1]=num1;
                    xz[num2][num1]=true;
                    xzlen[num2]++;
                    zxlen[num1]++;
                }
            }
            if(ch2=='Y'){
                if(!yz[num2][num1]){
                    c++;
                    yz[num2][num1]=true;
                    yzlen[num2]++;
                    zylen[num1]++;
                }
            }
        }
    }
    void cl2ear(){
            a=b=c=d=0;
            memset(xy,0,sizeof(xy));
            memset(yz,0,sizeof(yz));
            memset(xz,0,sizeof(xz));
            memset(xylen,0,sizeof(xylen));
            memset(yxlen,0,sizeof(xylen));
            memset(zylen,0,sizeof(xylen));
            memset(yzlen,0,sizeof(xylen));
            memset(xzlen,0,sizeof(xylen));
            memset(zxlen,0,sizeof(xylen));
    }
    int main(){
        int T;
        scanf("%d",&T);
        while(T--){
            scanf("%d%d",&n,&m);
            cl2ear();
            for(int i=0;i<m;i++){
                scanf("%s",buff);
                bool fl=false;
                char ch1,ch2;int num1=read1(),num2=read2();
                for(int j=0;buff[j];j++){
                    if(buff[j]=='X'||buff[j]=='Y'||buff[j]=='Z'){
                        if(!fl){
                            ch1=buff[j];
                            fl=true;
                        }
                        else {
                            ch2=buff[j];
                            break;
                        }
                    }
                }
                inset(ch1,ch2,num1,num2);
            }
            for(int i=0;i<b;i++){
                for(int j=1;j<=n;j++){
                    if(xy[xzheap[i][0]][j]&&yz[j][xzheap[i][1]])d++;
                }
            }
            int ans=n*a+n*b+n*c+d;
            int a=0;
            for(int i=1;i<=n;i++){
                a+=xylen[i]*xzlen[i]+yzlen[i]*yxlen[i]+zxlen[i]*zylen[i];
               // a+=yxlen[i]*zxlen[i]+zylen[i]*xylen[i]+xzlen[i]*yzlen[i];
            }
            ans-=a;
            printf("%d
    ",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    电脑开机自动上线(电脑开机之后自动将电脑的远程端口映射到服务器,可以通过其他设备进行连接,实现随时访问自己的电脑)
    批处理(bat)用来监测Windows网络状态脚本
    js取消点击事件
    uni-app 几个实用的功能
    前端几个比较方便的正则验证
    element.ui时间选择器
    Vue pc端项目打包后在nginx中无法正常浏览,点击页面出现404
    微信小程序之选项卡的实现方法
    文本溢出显示省略号
    分享几道前端面试题(3)
  • 原文地址:https://www.cnblogs.com/xuesu/p/4085693.html
Copyright © 2011-2022 走看看