Codeforces Round #143 (Div. 2) D. Magic Box

本文探讨了一个基于几何原理的简单问题:站在三维空间中特定位置的人如何计算正方体六个面上可见数字的总和。通过分析正方体相对位置与观察者视线的关系,解决此问题不仅涉及几何概念,还体现了数学在日常生活中的应用。案例研究展示了如何通过简单的逻辑判断来获取所需答案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开题目链接

D. Magic Box
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 xy and z (|x|, |y|, |z| ≤ 106) — the coordinates of Vasya's position in space. The second line contains three space-separated integers x1y1z1 (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.

Sample test(s)
input
2 2 2
1 1 1
1 2 3 4 5 6
output
12
input
0 0 10
3 2 3
1 2 3 4 5 6
output
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.


题意:有一个人站在(x,y,z)点上,而他的前方有一个(0,0,0)点的正方体,(0,0,0)的对立点的坐标为(a1,y1,z1).正方体的每一个面的正中央有一个值,如上图所示:zox面是:a1,其对立面是:a2; xoy面是:a3,其对立面是:a4;  yoz面是:a5其对立面是:a6;求你能看的的面的值的和。如果你的x坐标小于0的话,就能看到yoz面的a5,以此类推。

最近在学几何,本来打算大显身手的,结果发现是一个赤裸裸的水题。。。

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
  int x,y,z,x1,y1,z1;
  int a1,a2,a3,a4,a5,a6;
 scanf("%d%d%d%d%d%d",&x,&y,&z,&x1,&y1,&z1);
 cin>>a1>>a2>>a3>>a4>>a5>>a6;
int ans=0;
if(y<0)  ans+=a1;
if(y>y1) ans+=a2;
if(z<0)  ans+=a3;
if(z>z1) ans+=a4;
if(x<0)  ans+=a5;
if(x>x1) ans+=a6;
cout<<ans<<endl;
return 0;
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值