hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-11-09)
Description
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
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
Sample Input
3 2
Y=1,Z=3
X=3,Y=1
10 2
X=3,Y=3
Y=3,Z=3
Sample Output
19
#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的更多相关文章
- 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 ...
- hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1
F - Rotational Painting Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0
H - National Day Parade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 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 ...
- 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 ...
- 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 ...
- HDU 1796How many integers can you find(简单容斥定理)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0
Description A new Semester is coming and students are troubling for selecting courses. Students ...
- 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 ...
随机推荐
- Python3、Unicode、UTF-8、编码
text = u'你好,今天天气不错' text print(text) text = '\u4f60\u597d\uff0c\u4eca\u5929\u5929\u6c14\u4e0d\u9519' ...
- Redundant Paths---poj3177(双连通分量)
题目链接:http://poj.org/problem?id=3177 题意:有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新建多少条路,使 ...
- Linux学习 -->解决Ubuntu系统上 No command 'crond' found
前两天,准备在Ubuntu服务器上,定时执行Gitlab备份的命令,如下所示 编辑 vi /etc/crontab 文件,添加如下定时脚本 # edited by ouyang 2017-8-11 添 ...
- Select触发事件
案例1: <script type="text/JavaScript"> function gradeChange(){ var objS = document.ge ...
- Java-idea-Checkstyle自动化代码规范检查
一.概述 CheckStyle是SourceForge下的一个项目,提供了一个帮助JAVA开发人员遵守某些编码规范的工具.它能够自动化代码规范检查过程,从而使得开发人员从这项重要,但是枯燥的任务中解脱 ...
- 数据库知识,mysql索引原理
1:innodb底层实现原理:https://blog.csdn.net/u012978884/article/details/52416997 2:MySQL索引背后的数据结构及算法原理 ht ...
- 入坑-DM导论-第一章绪论笔记
//本学习笔记只是记录,并未有深入思考. 1.什么是数据挖掘? 数据挖掘是数据库中发现必不可少的一部分. 数据预处理主要包括(可能是最耗时的步骤): 1.融合来自多个数据源的数据 2.清洗数据以消除噪 ...
- validform.js+layer.js 表单验证样式
$("#formAdd").Validform({ tiptype: function (msg, o, cssctl) { if (o.type == 3) {//失败 laye ...
- CNN学习笔记:批标准化
CNN学习笔记:批标准化 Batch Normalization Batch Normalization, 批标准化, 是将分散的数据统一的一种做法, 也是优化神经网络的一种方法. 在神经网络的训练过 ...
- 前端学习笔记之CSS浮动浅析
很早以前就接触过CSS,但对于浮动始终非常迷惑,可能是自身理解能力差,也可能是没能遇到一篇通俗的教程. 前些天小菜终于搞懂了浮动的基本原理,迫不及待的分享给大家. 写在前面的话: 由于CSS内容比较多 ...