C - To Be an Dream Architect

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description: 
System Crawler  (2014-11-09)

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\n",ans);
}
return 0;
}

  

hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1的更多相关文章

  1. hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0

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

  2. hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1

    F - Rotational Painting Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  3. hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0

    H - National Day Parade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  4. hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1

    F - Computer Virus on Planet Pandora Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format ...

  5. hdu 3694 10 福州 现场 E - Fermat Point in Quadrangle 费马点 计算几何 难度:1

    In geometry the Fermat point of a triangle, also called Torricelli point, is a point such that the t ...

  6. hdu 4770 13 杭州 现场 A - Lights Against Dudely 暴力 bfs 状态压缩DP 难度:1

    Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money.&quo ...

  7. HDU 1796How many integers can you find(简单容斥定理)

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  8. hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

  9. hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

随机推荐

  1. Python3、Unicode、UTF-8、编码

    text = u'你好,今天天气不错' text print(text) text = '\u4f60\u597d\uff0c\u4eca\u5929\u5929\u6c14\u4e0d\u9519' ...

  2. Redundant Paths---poj3177(双连通分量)

    题目链接:http://poj.org/problem?id=3177 题意:有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新建多少条路,使 ...

  3. Linux学习 -->解决Ubuntu系统上 No command 'crond' found

    前两天,准备在Ubuntu服务器上,定时执行Gitlab备份的命令,如下所示 编辑 vi /etc/crontab 文件,添加如下定时脚本 # edited by ouyang 2017-8-11 添 ...

  4. Select触发事件

     案例1: <script type="text/JavaScript"> function gradeChange(){ var objS = document.ge ...

  5. Java-idea-Checkstyle自动化代码规范检查

    一.概述 CheckStyle是SourceForge下的一个项目,提供了一个帮助JAVA开发人员遵守某些编码规范的工具.它能够自动化代码规范检查过程,从而使得开发人员从这项重要,但是枯燥的任务中解脱 ...

  6. 数据库知识,mysql索引原理

    1:innodb底层实现原理:https://blog.csdn.net/u012978884/article/details/52416997 2:MySQL索引背后的数据结构及算法原理    ht ...

  7. 入坑-DM导论-第一章绪论笔记

    //本学习笔记只是记录,并未有深入思考. 1.什么是数据挖掘? 数据挖掘是数据库中发现必不可少的一部分. 数据预处理主要包括(可能是最耗时的步骤): 1.融合来自多个数据源的数据 2.清洗数据以消除噪 ...

  8. validform.js+layer.js 表单验证样式

    $("#formAdd").Validform({ tiptype: function (msg, o, cssctl) { if (o.type == 3) {//失败 laye ...

  9. CNN学习笔记:批标准化

    CNN学习笔记:批标准化 Batch Normalization Batch Normalization, 批标准化, 是将分散的数据统一的一种做法, 也是优化神经网络的一种方法. 在神经网络的训练过 ...

  10. 前端学习笔记之CSS浮动浅析

    很早以前就接触过CSS,但对于浮动始终非常迷惑,可能是自身理解能力差,也可能是没能遇到一篇通俗的教程. 前些天小菜终于搞懂了浮动的基本原理,迫不及待的分享给大家. 写在前面的话: 由于CSS内容比较多 ...