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 ...
随机推荐
- centos7 时间修改
转子 http://blog.csdn.net/kuluzs/article/details/52825331 在CentOS 6版本,时间设置有date.hwclock命令,从CentOS 7开始, ...
- 使用opencv-python画OpenCV LOGO
OpenCV2-Python 官方教程的练习 代码: #-*- coding:utf-8 -*- import numpy as np import cv2 img = np.zeros((512, ...
- launcher启动应用重启的BUG解决
最近遇到了一个问题,从launcher重新进入已经运行的应用会直接跳到应用的第一个界面. 经过对应用的跟踪,结合网络上的资料 http://stackoverflow.com/questions/19 ...
- Java核心技术-异常、断言和日志
程序发生错误时至少做到以下几点: *向用户通告错误 *保存所有的工作结果 *允许用户以妥善的形式退出程序 Java使用一种称为异常处理的错误捕获机制处理异常. 本章第一部分介绍Java的异常,第二部分 ...
- c++对象模型是什么,对象的内存布局和结构问题
在c++发明的初期对于c++对象模型的争论从来没有停止过直到标准委员会通过了最终的c++对象模型这件事情才变得尘埃落定.C++对象模型可能是最不需要去解释的,但是又是不得不去说的因为c++的入门最先接 ...
- Mysql Join语法以及性能优化
引言 内外联结的区别是内联结将去除所有不符合条件的记录,而外联结则保留其中部分.外左联结与外右联结的区别在于如果用A左联结B则A中所有记录都会保留在结果中,此时B中只有符合联结条件的记录,而右联结相反 ...
- ECS 游戏架构 理解
转载自:http://blog.csdn.net/i_dovelemon/article/details/25798677 理解 组件-实体-系统 (ECS \CES)游戏编程模型 - 博客频道 ...
- 10个实用的Django技巧和建议
Django 作为一个杰出的Python开源框架,或许得不到和其它流行框架如Rails这样多的赞美,但是它和其他框架一样精炼,非常注重DRY(Don’t Repeat Yoursef)原则.组件的重用 ...
- c#反射泛型方法
private void GetByEnumType() { var EnumType = Context.Request["EnumType"] ?? ""; ...
- LWIP协议栈1
STM32F4自带的MAC,而没有PHY纯模拟电路部分,没有把PHY做进STM32F4是因为会对芯片的功耗有影响,同时芯片的体积会增大等原因. MAC与PHY的通信接口是MII以及RMII方式. MD ...