Finding if the x and y coordinate is within a view is enclosed by two intersecting rectangles, in java [closed]

Say I have this view with two subviews A and B, A and B has a color property mColor,

enter image description here

I want a function in the parent view that has this signature: int getColor(int x, int y), which for any given x and y coordinate, return the color at that position, if the x and y coordinates land and the two shapes are overlapped, return the average color of A and B

The problem I am running into is i see myself doing a lot of conditional checks, checking if A is left of B or if A is right of B etc. I feel like I am missing some key intuition

I have a Point class that handles the coordinates”

public class Point {     private final int mX;     private final int mY;      public Point(int mX, int mY) {         this.mX = mX;         this.mY = mY;     }      public int getX() {         return mX;     }      public int getY() {         return mY;     } } 

Here is my subview class:

public class Chart  {      private int mColor;     private Point mTopLeft;     private Point mBottomRight;      public Point getTopLeft() {         return mTopLeft;     }      public Point getBottomRight() {         return mBottomRight;     }      public Chart(int mColor, Point topLeft, Point bottomRight) {         this.mColor = mColor;         this.mTopLeft = topLeft;         this.mBottomRight = bottomRight;     }      public int getColor() {         return mColor;     }      public Point getTopRightCorner() {         return new Point(getBottomRight().getX(), getTopLeft().getY());     }      public Point getBottomLeftCorner() {         return new Point(getTopLeft().getX(), getBottomRight().getY());     } } 

My parent view class:

public class View {      private Chart mChartA;     private Chart mChartB;      public View(Chart chartA,                 Chart chartB) {         mChartA = chartA;         mChartB = chartB;     }      public boolean doChartsOverlap() {         boolean isOverlapped = true;          if(isChartALeftOfChartBInX() || isChartARightOfChartBInX()) {             isOverlapped = false;         }          if(isChartABottomOfChartBInY() || isChartATopOfChartBInY()) {             isOverlapped = false;         }         return isOverlapped;     }      public final boolean isChartALeftOfChartBInX() {         return mChartA.getBottomRight().getX() <= mChartB.getTopLeft().getX();     }      public final boolean isChartARightOfChartBInX() {         return mChartA.getTopLeft().getX() >= mChartB.getBottomRight().getX();     }      public final boolean isChartATopOfChartBInY() {         return mChartA.getBottomRight().getY() <= mChartB.getTopLeft().getY();     }      public final boolean isChartABottomOfChartBInY() {         return mChartA.getTopLeft().getY() >= mChartB.getBottomRight().getY();     }      public void setChartA(Chart mChartA) {         this.mChartA = mChartA;     }      public void setChartB(Chart mChartB) {         this.mChartB = mChartB;     } } 

Finding the count of 0’s bounded by all 1’s

Given N * M 2-D matrix find out all the 0’s which are completely bounded by the all 1’s. ( This is not any online platform question ).


Input : Row : 3 , Col : 3

1 1 1

1 0 1

1 1 1

Output : 1

Input : Row: 2 Col: 2

1 1

1 1

Output : 0

Input : Row: 4 Col: 4

1 0 1 0

1 1 1 0

1 0 1 1

1 1 1 1

Output : 1

Input : Row : 4 Col : 5

1 1 1 0 1

1 0 1 1 1

1 1 1 0 1

0 0 1 1 1

Output : 2

I have tried to solve this question but not able to think about the optimized solution.

My Algorithm ( Brute Force Algorithm ):

  1. Generating the all the Sub-Matrix of a given matrix
  2. Checking whether given sub-matrix satisfies my given condition or not.
  3. Increment the counter repeat 1 to 3.

Could anyone please help me out to think about more optimized approach to solve the above question ?

Finding an algorithm that after removing k edges we get an acyclic graph

Assuming there’s an algorithm that can decide belonging to ACYCLIC in polynomial time. How can I use this algorithm in another algorithm that upon the input of a directed graph and a positive number k, returns k edges that after removing them, the graph becomes acyclic(has no cycles). there are no weights in the graph, just regular directed graph.

ACYCLIC is for a directed graph that is acyclic.

What I am trying to do is something like this: For a directed graph G=(V,E), Assuming there exists an algorithm isacyclic that returns true or false whether given graph is acyclic or not:

1)select a vertex and begin traverse the graph

2)while number of edges > 3 and we did not finish traversing the graph(3 edges can form a cycle, and i need at least one more because k should be positive, meaning number of edges that upon removing i’ll obtain an acyclic graph)

2.1)if (number of edges traversed – 3) greater than k

2.2)if isacyclic returns false:

2.3)try eliminating last edge and rerun isacyclic, if returns true – add edge to a list/stack and continue traversing without it

if at the end of the algorithm there are no k edges in the list/stack – reject

else accept

The algorithm I wrote was general idea of what I am looking for. I assume that there exists an algorithm that can decide belonging to ACYCLIC in a polynomial time for the questions sake.

What I am looking for is an algorithm that for a directed graph g and a positive number k, can give me k edges that when I remove them, I get an acyclic graph

The algorithm should be polynomial in regards to its input size.

Thank you very much!

Finding bound function of loop invariant

In Programming in the 1990s, by Edward Cohen, the author gives an example of a bound function.

For example, if we have $ B \equiv 10 – n$ where $ n = 0$ , say, then $ B$ will eventually be falsified if 10 – n is decreased. Thus we would need to choose for our bound function $ t = 10 – n$ . Decreasing t will eventually falsify $ B$ .

How did he find such bound function? Is it dependent on some variable, like this: $ t(n) = 10 – n$ ?

Finding encryption algorithm from known and encrypted password strings [duplicate]

I am working with a piece of software which seems to use some type of lightweight, “home baked” password encryption algorithm.

I know a number of clear text passwords as well as their corresponding encrypted as they are stored in the database — Does anyone know of a tool or a means to find the underlying algorithm and/or hash type which might be used? I would like to be able to decrypt and use these in a use-case application of my own.

Examples (clear text -> encrypted):

test123 -> 2404483248 tb ->      43971963 ks ->      43912691 mm ->      43937163 et ->      43941139 


need helping finding ip address from a whatsapp phone number or other services like it

my wife has has a stalker for 4 years continuously making new phone numbers and she cant change the number because its for work. she works in the adult entertainment industry and this person is trying to ruin her life, and im fed up. he has been making fake reviews and fake appointments. im trying to find a way to get this persons ip address, possibly block it from sending msgs of any kind from any fake number service. i really dont know what my options are. if anyone can help i would appreciate it.

finding the parent index in an interval heap (stored on an array) given a child index

an interval heap is a binary tree stored on an array where the size of each node is 2.

i would like to be able to find the index of a parent and find one of the child indices given the index of a node.

an example of an interval trees indices would be:

         [0,1]      [2,3]     [4,5]  [6,7][8,9][10,11][12,13] 


         [1,2]      [3,4]     [5,6]  [7,8][9,10][11,12][13,14] 

Algorithm for finding “mean center” of unweighted graph

I have a large sparse unweighted undirected graph (20M vertices, 60M edges) and would like to find what I’m calling the “mean center” (the vertex w/ shortest mean distance to all other vertices. Does this already have a name?). I know of an $ O(N^2)$ solution: Starting at every vertex: BFS to calculate the mean distance to all other vertices, choose the minimum. But $ N^2$ is too slow for a graph this size, is there any way to calculate the “mean center” in faster than $ N^2$ time? Are there any good approximation algorithms? Or more efficient algorithms which find some similar “center” of a graph?

Finding Your Competitors Facebook Ads Is Easier Than You Think

If you’re intimidated about doing market research, don’t be. It’s significantly easier than you think it is, that we’ll promise. Thanks to the election scandal, Facebook has purposed to be more transparent when it comes to ads and customer data. And this means that they have given us a powerful tool in that we can now click through competitors' ads in less time than it takes to ask if it's possible. The first step is to navigate to your competitor's Facebook page. You’ll see a button on the…

Finding Your Competitors Facebook Ads Is Easier Than You Think