Hi All,
Problem Statement:
Given a parallelepiped with coordinates of diagonal as (0,0,0) and (x,y,z), another point (x,y,z) having an observer you need to find sum of all the values observer can see. Every face has a value written over it.
For more details: http://codeforces.com/problemset/problem/231/D
My Approach: Observer can look at any face's value only and only if he is on opposite side of parallelepiped with respect to that face. For example: Observer can see value written on Z=0 plane only and only if coordinates of his value are (Z<0), otherwise he will always be on other side of the face and as parallelepiped is not transparent, he can't look at the number.
Implementation:
Link: http://codeforces.com/contest/231/submission/41682545
Problem Statement:
Given a parallelepiped with coordinates of diagonal as (0,0,0) and (x,y,z), another point (x,y,z) having an observer you need to find sum of all the values observer can see. Every face has a value written over it.
For more details: http://codeforces.com/problemset/problem/231/D
My Approach: Observer can look at any face's value only and only if he is on opposite side of parallelepiped with respect to that face. For example: Observer can see value written on Z=0 plane only and only if coordinates of his value are (Z<0), otherwise he will always be on other side of the face and as parallelepiped is not transparent, he can't look at the number.
Implementation:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
using namespace std; | |
#define ll long long | |
int main(){ | |
ll faceValues[6]; | |
ll observerCoordinate[3]; | |
ll endPoints[3]; | |
for(int i=0; i<3; i++) cin>>observerCoordinate[i]; | |
for(int i=0; i<3; i++) cin>>endPoints[i]; | |
for(int i=0; i<6; i++) cin>>faceValues[i]; | |
ll totalValue=0; | |
if(observerCoordinate[1]<0) totalValue+=faceValues[0]; | |
if(observerCoordinate[1]>endPoints[1]) totalValue+=faceValues[1]; | |
if(observerCoordinate[2]<0) totalValue+=faceValues[2]; | |
if(observerCoordinate[2]>endPoints[2]) totalValue+=faceValues[3]; | |
if(observerCoordinate[0]<0) totalValue+=faceValues[4]; | |
if(observerCoordinate[0]>endPoints[0]) totalValue+=faceValues[5]; | |
cout << totalValue << endl; | |
return 0; | |
} |
this is good very helpful to me.
ReplyDeletei also have programming related blog pythongarden.blogspot.com visit this and help me with pythonprogramming. you are a best blog updater
http://pythongarden.blogspot.com/?m=1
ReplyDeletehttp://pythongarden.blogspot.com/?m=1
ReplyDeletethis is good very helpful to me.
ReplyDeletei also have programming related blog pythongarden.blogspot.com visit this and help me with pythonprogramming. you are a best blog updater