HDU 3682 水模拟

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;
}
时间: 2024-10-12 01:47:56

HDU 3682 水模拟的相关文章

HDU 4903 (模拟+贪心)

Fighting the Landlords Problem Description Fighting the Landlords is a card game which has been a heat for years in China. The game goes with the 54 poker cards for 3 players, where the “Landlord” has 20 cards and the other two (the “Farmers”) have 1

【水?模拟】10495 - 谁拿了最多奖学金

[水·模拟]10495 - 谁拿了最多奖学金 Time Limit: 1000MS Memory Limit: 32768KB [问题描述] 某校的惯例是在每学期的期末考试之后发放奖学金.发放的奖学金共有五种,获取的条件各自不同: 1)     院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生均可获得: 2)     五四奖学金,每人4000元,期末平均成绩高于85分(>85),并且班级评议成绩高于80分(>80)的学生均可获得:

HDU 4968 (水dp 其他?)

1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <vector> 5 #include <map> 6 using namespace std; 7 const int inf = 0x3f3f3f3f; 8 const int MAX = 200+10; 9 double GPA[10],dp1[20][30000],dp2[20][30000

hdu 4964 Emmet(模拟)

题目链接:hdu 4964 Emmet 题目大意: 给定语句,按照语法翻译并输出. 解题思路:用递归模拟文法分析,主要注意几点: 括号并且的情况:(fuck)(you) 括号嵌套的情况:((fuck.you)) 优先输出id,然后是class(题目中有说) 乘法的部分:fuck*2>you*3 (每次执行fuck时,you的地方同样被执行了3次) 其他跑出样例基本没问题,具体看代码. #include <cstdio> #include <cstring> #include

HDU 4891 简单模拟

The Great Pan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1035    Accepted Submission(s): 355 Problem Description As a programming contest addict, Waybl is always happy to take part in vario

hdu 4194(模拟)

符合三者之一的则不满足规定,求不满足规定的个数.直接模拟. 1.被同一个人审查多次 2.被和自己同一组织的审查 3.被审查次数不等于k 代码如下: 1 /************************************************** 2 * Author : xiaohao Z 3 * Blog : http://www.cnblogs.com/shu-xiaohao/ 4 * Last modified : 2014-06-28 17:36 5 * Filename :

hdu 4416 水题 浙大计算机研究生复试上机考试-2005年 可是发现自己写代码有问题

Spring3与Hibernate4整合时出现了nested exception is java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider. hibernate3的时候,用spring来控制sessionfactory用的可以是org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean,因为用的是hibernate4所以照猫画

hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥

C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3682 Appoint description:  System Crawler  (2014-11-09) Description The “dream architect” is the key role in a team o

HDU-1037-Keep on Truckin&#39;(HDU最水的题没有之一,为了练英语就来吧)

Keep on Truckin' Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10324    Accepted Submission(s): 7147 Problem Description Boudreaux and Thibodeaux are on the road again . . . "Boudreaux, we ha