D. Magic Box(几何)
One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (x1, y1, z1). The six faces of the box contain some numbers a1, a2, ..., a6, exactly one number right in the center of each face.
The numbers are located on the box like that:
- number a1 is written on the face that lies on the ZOX plane;
- a2 is written on the face, parallel to the plane from the previous point;
- a3 is written on the face that lies on the XOY plane;
- a4 is written on the face, parallel to the plane from the previous point;
- a5 is written on the face that lies on the YOZ plane;
- a6 is written on the face, parallel to the plane from the previous point.
At the moment Vasya is looking at the box from point (x, y, z). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly the ai numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees some ai = 6, then he can't mistake this number for 9 and so on).
Input
The fist input line contains three space-separated integers x, y and z (|x|, |y|, |z| ≤ 106) — the coordinates of Vasya's position in space. The second line contains three space-separated integers x1, y1, z1 (1 ≤ x1, y1, z1 ≤ 106) — the coordinates of the box's vertex that is opposite to the vertex at point (0, 0, 0). The third line contains six space-separated integers a1, a2, ..., a6 (1 ≤ ai ≤ 106) — the numbers that are written on the box faces.
It is guaranteed that point (x, y, z) is located strictly outside the box.
Output
Print a single integer — the sum of all numbers on the box faces that Vasya sees.
Example
2 2 2
1 1 1
1 2 3 4 5 6
12
0 0 10
3 2 3
1 2 3 4 5 6
4
Note
The first sample corresponds to perspective, depicted on the picture. Vasya sees numbers a2 (on the top face that is the darkest), a6 (on the right face that is the lightest) and a4 (on the left visible face).
In the second sample Vasya can only see number a4.
本来是用暴力来接的解出来了,但是今天看了被人的代码,发现这道题其实很简洁,怎么说呢,还是想不到那么好的办法,不过看过之后能够想到还是很值得的
#include<cstdio>
int main()
{
int x,y,z,x1,y1,z1;
int a1,a2,a3,a4,a5,a6;
scanf("%d %d %d",&x,&y,&z);
scanf("%d %d %d",&x1,&y1,&z1);
scanf("%d %d %d %d %d %d",&a1,&a2,&a3,&a4,&a5,&a6);
int ans=0;
if(x<0) ans+=a5;
if(x>x1) ans+=a6;
if(y<0) ans+=a1;
if(y>y1) ans+=a2;
if(z<0) ans+=a3;
if(z>z1) ans+=a4;
printf("%d\n",ans);
return 0;
}
D. Magic Box(几何)的更多相关文章
- 【hihocoder】 Magic Box
题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...
- hihocoder 1135 : Magic Box
#1135 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. Whe ...
- BestCoder Round #25 1002 Harry And Magic Box [dp]
传送门 Harry And Magic Box Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- 微软2016校园招聘在线笔试之Magic Box
题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...
- HDU 5155 Harry And Magic Box --DP
题意:nxm的棋盘,要求每行每列至少放一个棋子的方法数. 解法:首先可以明确是DP,这种行和列的DP很多时候都要一行一行的推过去,即至少枚举此行和前一行. dp[i][j]表示前 i 行有 j 列都有 ...
- [HDOJ 5155] Harry And Magic Box
题目链接:HDOJ - 5155 题目大意 有一个 n * m 的棋盘,已知每行每列都至少有一个棋子,求可能有多少种不同的棋子分布情况.答案对一个大素数取模. 题目分析 算法1: 使用容斥原理与递推. ...
- 【HDOJ】5155 Harry And Magic Box
DP.dp[i][j]可以表示i行j列满足要求的组合个数,考虑dp[i-1][k]满足条件,那么第i行的那k列可以为任意排列(2^k),其余的j-k列必须全为1,因此dp[i][j] += dp[i- ...
- hihoCoder题目之Magic Box
#include <iostream> #include <cmath> #include <cstdio> using namespace std; void s ...
- HDU-5155 Harry And Magic Box
题目描述 在\(n*m\)的矩阵内每一行每一列都有钻石,问钻石分布的种类? 答案有可能很大,所以输出答案对\(1000000007\)取模. Input 对于每个测试用例,有两个整数\(n\)和\(m ...
随机推荐
- vs2012 未找到与约束 ContractName Microsoft.VisualStudio.Utilities.IContentTy...
错误的大致内容,不能加载某个文件,需要修改web.config文件或者重命名新建.... 周末360大神帮我修复了一下电脑,然而,这一修复导致周一早上的一连串状况, 以上就是错误本尊,刚开始以为同事提 ...
- CCS5连接调试C64X系列DSP核
CCS从3.3改版为5.X之后,CCS 变化很大.DaVinci芯片中DSP的调试步骤也不同了.这里介绍下在CCS里如何调试DaVinci的DSP核心 1. 创建CCS V5版本的project 本人 ...
- 【算法】2-sat问题【模板】
什么是2-sat问题 有n个布尔型变量xi,另外m个需要满足的条件.每个条件都是“xi为真/假或者xj为真/假”.这句话中的“或者”意味着两个条件中至少有一个正确.2-sat问题的目标是给每个变量赋值 ...
- 【总结整理】UGC内容
除了内容了产品,还有什么适合引入UGC? :引发讨论,诱导参与,然后促成销售. User Generated Content,也就是用户生成内容的意思. 购买类产品,内容催生购买 1.为用户购买提供思 ...
- UNITY的UI之Pivot与Anchor区别
Pivot Rotations, size, and scale modifications occur around the pivot so the position of the pivot a ...
- Python学习笔记_读Excel去重
读取一个Excel文件,按照某列关键字,如果有重复则去掉 这里不介绍所有的解决办法,只是列出一个办法. 软件环境: OS:Win10 64位 Python 3.7 测试路径:D:\Work\Pytho ...
- Java基础——常用类型转换
关于类型转化问题: (1)String--------->char / char[ ] String str = "ab"; char str1 = str.charAt(0 ...
- Photo3
Story: 这是一个简朴的家,有用旧了的风扇,木制的桌子,桌子上放了未完成的功课,还有一只正在睡觉的猫.阳光从窗户照进来,微风轻轻的吹着.想象你是坐在窗边吹风的小女孩,你的眼睛正眺望着不远处的风景, ...
- mysql:unknown variable 'default -collation=utf8_general_ci'
无法登陆,因为在配置文档中设置了默认编码方式 将它注释掉,问题就解决了 在utf8_bin中你就找不到 txt = 'A' 的那一行, 而 utf8_general_ci 则可以.utf8_gener ...
- 基于JDBC的数据库连接池技术研究与应用
引言 近年来,随着Internet/Intranet建网技术的飞速发展和在世界范围内的迅速普及,计算机 应用程序已从传统的桌面应用转到Web应用.基于B/S(Browser/Server)架构的3层开 ...