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

原创 2016年08月28日 16:39:54

原题链接

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.

Examples
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.


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;

int main(){
	
//	 freopen("in.txt", "r", stdin);
	 int a[7];
	 int x, y, z, x1, y1, z1;
	 
	 scanf("%d%d%d%d%d%d", &x, &y, &z, &x1, &y1, &z1);
	 for(int i = 1; i <= 6; i++)
	  scanf("%d", a+i);
	int s = 0;
	if(y > y1)
	 s += a[2];
	if(y < 0)
	 s += a[1];
	if(z > z1)
	 s += a[4];
	if(z < 0)
	 s += a[3];
	if(x > x1)
	 s += a[6];
	if(x < 0)
	 s += a[5];
	cout << s << endl;
	
	return 0;
} 


版权声明:本文为博主原创文章,未经博主允许不得转载。

数学推公式——较难——Codeforces Round #187 (Div. 2)

题目链接: http://codeforces.com/contest/315/problem/C C. Sereja and Contest time limi...
  • CS_liuqing
  • CS_liuqing
  • 2013年06月16日 15:34
  • 1987

Codeforces Round #280 (Div. 2) D:二分+浮点数模型转为整型模型 E:数学(取模)

比赛地址: http://codeforces.com/contest/492 官方题解: Codeforces Round #280 (Div. 2) Editoria...
  • csuhoward
  • csuhoward
  • 2014年12月02日 14:14
  • 1104

Codeforces 375D 数据结构(好题中的好题, 4解)

题目链接:http://codeforces.com/problemset/problem/375/D 全部代码: 题意:给你一棵树n个点,m次询问(n=100000,m=100000),每个节点有一...
  • c3568
  • c3568
  • 2014年03月25日 19:38
  • 1408

Codeforces Round #143 (Div. 2) B - Magic, Wizardry and Wonders 数学

Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a mag...
  • angle555945
  • angle555945
  • 2012年10月08日 12:06
  • 1205

Codeforces Round #143 (Div. 2) B. Magic, Wizardry and Wonders

B. Magic, Wizardry and Wonders time limit per test 2 seconds memory limit per test 256 m...
  • u011111528
  • u011111528
  • 2014年04月08日 12:46
  • 818

Codeforces Round #350 (Div. 2) D1,D2Magic Powder(二分)

D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes ...
  • longshanxiaoxuesheng
  • longshanxiaoxuesheng
  • 2016年05月06日 20:23
  • 430

Codeforces Round #143 (Div. 2) C. To Add or Not to Add 胡搞

A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number th...
  • angle555945
  • angle555945
  • 2012年10月09日 12:09
  • 958

Codeforces Round #143 (Div. 2)

­­­­­好吧…Rating在上次#141之后1756.#143只有DIv2于是就打酱油来了.最后一题Tarjan_LCA忘光光了,比赛完才写的. 前四题比较简单 Rank80   A: 水. ...
  • whimsyChen
  • whimsyChen
  • 2012年10月08日 22:24
  • 251

Codeforces Round #143 (Div. 2) (ABCD 思维场)

Codeforces Round #143 (Div. 2) (ABCD 思维场)
  • Tc_To_Top
  • Tc_To_Top
  • 2015年07月18日 18:58
  • 968

Codeforces Round #242 (Div. 2) C: Magic Formulas 神奇的异或算式

原题链接:Codeforces 424C - Magic Formulas 题目大意: 大致思路:
  • u012952004
  • u012952004
  • 2014年04月25日 20:34
  • 421
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #143 (Div. 2)-D. Magic Box
举报原因:
原因补充:

(最多只允许输入30个字)