HDU 3682 水類比,hdu3682水類比

來源:互聯網
上載者:User

HDU 3682 水類比,hdu3682水類比

n*n*n的圖形,m條線,每條線上的方格被刪除,問一共刪除了多少個方格

ans=m*n ,然後判斷一下直線相交的交點,去重即可

#include "stdio.h"#include "string.h"int xy[1010][1010],xz[1010][1010],yz[1010][1010],hash[1010];struct node{    int x,y,z;} mark[1010];int main(){    int Case,n,m,i,j,cnt,a,b,ans,sum;    char ch1,ch2;    scanf("%d",&Case);    while (Case--)    {        scanf("%d%d",&n,&m);        if (m==0)        {            printf("0\n");            continue;        }        memset(xy,0,sizeof(xy));        memset(xz,0,sizeof(xz));        memset(yz,0,sizeof(yz));        cnt=0;        while (m--) // 去重邊        {            getchar();            scanf("%c=%d,%c=%d",&ch1,&a,&ch2,&b);            if (ch1=='X' && ch2=='Y' && xy[a][b]==0)            {                mark[cnt].x=a;                mark[cnt].y=b;                mark[cnt++].z=-1;                xy[a][b]=1;            }            if (ch1=='Y' && ch2=='X' && xy[b][a]==0)            {                mark[cnt].x=b;                mark[cnt].y=a;                mark[cnt++].z=-1;                xy[b][a]=1;            }            if (ch1=='X' && ch2=='Z' && xz[a][b]==0)            {                mark[cnt].x=a;                mark[cnt].z=b;                mark[cnt++].y=-1;                xz[a][b]=1;            }            if (ch1=='Z' && ch2=='X' && xz[b][a]==0)            {                mark[cnt].x=b;                mark[cnt].z=a;                mark[cnt++].y=-1;                xz[b][a]=1;            }            if (ch1=='Y' && ch2=='Z' && yz[a][b]==0)            {                mark[cnt].y=a;                mark[cnt].z=b;                mark[cnt++].x=-1;                yz[a][b]=1;            }            if (ch1=='Z' && ch2=='Y' && yz[b][a]==0)            {                mark[cnt].y=b;                mark[cnt].z=a;                mark[cnt++].x=-1;                yz[b][a]=1;            }        }        ans=n;        for (i=1; i<cnt; i++) //去重點        {            memset(hash,0,sizeof(hash));            sum=n;            for (j=0; j<i; j++)             {                if (mark[i].x==mark[j].x && mark[i].x!=-1)                {                    if (mark[i].y==-1 && mark[j].y!=-1)                    {                        if (hash[mark[j].y]==0)                            sum--;                        hash[mark[j].y]=1;                    }                    if (mark[i].z==-1 && mark[j].z!=-1)                    {                        if (hash[mark[j].z]==0)                            sum--;                        hash[mark[j].z]=1;                    }                }                if (mark[i].y==mark[j].y && mark[i].y!=-1)                {                    if (mark[i].x==-1 && mark[j].x!=-1)                    {                        if (hash[mark[j].x]==0)                            sum--;                        hash[mark[j].x]=1;                    }                    if (mark[i].z==-1 && mark[j].z!=-1)                    {                        if (hash[mark[j].z]==0)                            sum--;                        hash[mark[j].z]=1;                    }                }                if (mark[i].z==mark[j].z && mark[i].z!=-1)                {                    if (mark[i].x==-1 && mark[j].x!=-1)                    {                        if (hash[mark[j].x]==0)                            sum--;                        hash[mark[j].x]=1;                    }                    if (mark[i].y==-1 && mark[j].y!=-1)                    {                        if (hash[mark[j].y]==0)                            sum--;                        hash[mark[j].y]=1;                    }                }            }            ans+=sum;        }        printf("%d\n",ans);    }    return 0;}





聯繫我們

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