hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-11-05)
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
感想:简单的容斥原理,但是统计得头晕眼花,输入也给人找麻烦,姿势还是不好
思路:每次消掉一行,比如消掉的是坐标为(x0,y0),平行z轴的某行,也就是不能有坐标为(x0,y0,*)的三维整数点满足题意,同理,对于(*,y0,z0),(x0,*,z0)也是,(*通配),所以容斥,得到总数
#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];
}
ans-=a;
printf("%d\n",ans);
}
return 0;
}
hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0的更多相关文章
- hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1
C - To Be an Dream Architect Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- hdu 4771 13 杭州 现场 B - Stealing Harry Potter's Precious 暴力bfs 难度:0
Description Harry Potter has some precious. For example, his invisible robe, his wand and his owl. W ...
- 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 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 ...
- hdu 3696 10 福州 现场 G - Farm Game DP+拓扑排序 or spfa+超级源 难度:0
Description “Farm Game” is one of the most popular games in online community. In the community each ...
- 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 ...
随机推荐
- 洛谷P1613 跑路 图论
正解:倍增+图论 解题报告: 传送门! 话说这题是真滴很妙啊,,,大概港下QwQ 首先看懂这道题,它是说,只要是1<<k的都能1s跑过,而且每条边的长度都是1,就是说一秒可以跑过1< ...
- IDEA阿里巴巴Java开发规约插件使用
前言 2017年2月9日,首次公布<阿里巴巴Java开发手册>; 2017年9月25日,阿里巴巴集团发布了<阿里巴巴Java开发手册>PDF终极版; 2017年10月14日,在 ...
- jQuery实现节点克隆、替换和互换
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- windows监听socket和标准输入
原来的代码 def input_command(self): msg = raw_input('\nPlease input the command:') remote_id = raw_input( ...
- IntelliJ idea的初次使用
1. 首次使用Idea工具,需要安装.我安装的版本是14.0.2.安装包下载地址 http://pan.baidu.com/s/1gfFkrzt 2. 安装SVN. 3.配置JDK. 4.配置mave ...
- stm32_CAN总线知识(转)
源: stm32_CAN总线知识
- MySQL的GTID复制
从mysql5.6开始引入全局事务标识符(GTID),即每个事务都有一个唯一的标识符.服务器上的每个事务都被分配一个唯一的事务标识符,这是一个64位非零的数值,根据事务提交的顺序分配.GTID的构成是 ...
- Vue学习笔记之Vue的模板字符串
0x00 模板字符串 传统的JavaScript语言,输出模板通常是这样的写的. $('#result').append( 'There are <b>' + basket.count + ...
- 2018-2019-1 20189215 《Linux内核原理与分析》第八周作业
可执行程序工作原理 <庖丁解牛>第七章书本知识总结 "目标文件"是指编译器生成的文件,"目标"指的是目标平台,例如x86或x64,它决定了编译器使用 ...
- 20145311 《Java程序设计》第七周学习总结
20145311 <Java程序设计>第七周学习总结 教材学习内容总结 第十二章 Lambda Lambda表达式会使程序更加地简洁,在平行设计的时候,能够进行并行处理. 第十三章 时间与 ...