Showing posts with label div2D. Show all posts
Showing posts with label div2D. Show all posts

18 August 2018

Codeforces Round #151 D : Colorful Graph

Hi All,

I will be providing editorial for one of the problem from CF #151 today.
Link of Problem: http://codeforces.com/contest/246/problem/D

Problem Statement: All the nodes are given some color between [1-1e5]. Our task is to find one color having maximum different kind of neighbors. As per my approach, I though of making a map of 100000 size. What we can do is that on getting every edge, if both vertex has different color, we can put this in our map.
Now as we want lexicographical smallest value of vertex having same cardinality, we traverse our map in sorted order of vertexes. We simple pick the one with highest cardinality and lowest vertex number.
Hope code will resolve doubts in case you have.
Implementation:
Feel free to comment in case you are not able to follow up.

17 August 2018

Codeforces Round #143 D: Magic Box

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