Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We want to test the efficiency of new sheet metal forming process. After forming we measure the deviation from the intended thickness.

The raw data can be visualised as a square grid of measurements ranging from 0 (correct thickness) to 5 (high deviation from correct thickness).

We want to find large areas of high deviation from the correct thickness. To do so, We calculate a score for each location in the grid. The score is determined by adding the location's own deviation,
to its surrounding deviations.

For Example, in a grid:
4 | 2 | 3 | 2
0 | 1 | 2 | 2
1 | 3 | 0 | 2
2 | 0 | 1 | 5
The score for location `(1,1)` is follows:

score(1,1) = 4 + 2 + 3 + 0 + 1 + 2 + 1 + 3 + 0 = 16

When dealing with locations around the edge of the grid the score
should ignore values outside the grid. For instance the score of
location `(0, 0)` is as follows:
4 | 2 | 3 | 2
0 | 1 | 2 | 2
1 | 3 | 0 | 2
2 | 0 | 1 | 5
score(0,0) = 4 + 2 + 0 + 1 = 7

Write a function:
class Solution { public string solution (int T, int N, int[ ] V); }
that, given an integer `T`, an integer `N` and a zero-indexed array `V`
consisting of `N*N` integers, return a list of the `T` highest scores and
their locations.

Each location and score should be formatted:
(x, y, score)

Where `(x,y)` is the zero-indexed vector from the top-left of the grid.

The list should be returned as a string:
(x1, y1, score1) (x2, y2, score2) (x3, y3, score3)

If there are multiple locations with the same score, prefer locations
to the top-left e.g. `(1, 0 ,20)(2, 0, 20)(1, 1 ,20)`

The inputs asking for the top1 measurement in the grid:
4 | 2 | 3 | 2
0 | 1 | 2 | 2
1 | 3 | 0 | 2
2 | 0 | 1 | 5
Would be:

T = 1
N = 4
V = [4, 2, 3, 2, 0, 1, 2, 2, 1, 3, 0, 2, 2, 0, 1, 5]

What I have tried:

I didn't understand properly what exactly the output is. I am not good at statistics. Can anyone help me to find the solution? Thanks
Posted
Updated 30-Aug-18 5:00am
v2
Comments
dan!sh 30-Aug-18 10:10am    
You need to do this in C#?

1 solution

First of all, this is not statistics. It is just a score evaluation and then sorting of the scores and that is the way you should approach the problem. Since this seems remarkably like a homework problem and you didn't ask a question about code I will not give any code. That is for you to do.

First, write yourself a method that accepts the input and process it into a grid of values. A vector of vectors is one option to store the grid.

Then you need a method that computes a score given the grid, its size, and a location in the grid (x,y). It could return the score as an integer. Here's where things get a little tricky. You need to save the scores along with the location and possibly the distance from the top left so you can sort the scores easily. I would probably use a structure with each of these values as the members - score, x, y, and distance. You can save the structures in a vector.

Next, sort the vector of scores to get them in order. You will need to have a secondary criterion for the sort which is the distance from the top left corner for when the scores match and a tertiary condition for when the scores and distances match. For example, the coordinates (1,2) and (2,1) are the same distance from the top left so which one comes first? The tertiary condition will decide that.

Lastly, given the sorted vector of scores, write the top T scores into a string in the specified format.

I would separate the problem into these four components and deal with them one at a time.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900