Thread: Can someone solve this programs?

  1. #1
    Registered User
    Join Date
    Jan 2019
    Posts
    3

    Question Can someone solve this programs?

    1! Little Tom was bad, and for the punishment he was given the duty to paint the wall. The wall can be presented as a 2D array with N rows and M columns. Tom has a very strange brush with which he can in either row give the paint or the first Ai columns or the last
    M-Ai columns. To Tom, each column is boring as much as the product of the number of painted and unpainted fields in that column. The total wall boredom is equal to the sum total of the boredom of all columns. Help Tom and calculate the least possible wall boredom after staining.


    Input 1:
    2 3
    1
    2

    Output 1: 1
    Input 2:
    4 4
    2
    1
    4
    1
    Output 2: 6
    ~~~~~~~~~~~~~~~~~~~~~~~~
    Problem 2:

    The notorious master of all rodents, Black, intends to subjugate the whole world. However, a good part of Perine Farm will serve for now.

    Perin's farm can be presented as a matrix M of dimension N × N where Mij field contains one number - the sort of apples that Pera breeds in that field. It is known that Pera marks the varieties with some numbers between 1 and K.

    Strange roads are rocks, and Cirlet's regular army can subjugate only the best territories. We say that the territory is suitable if it is rectangular in shape, it contains only one variety of apples and this variety is located only within that territory.
    Hiring elite rats costs too much, and Çrleta is interested in the extent to which Perina Farm has a suitable territory (he himself does not know why). Since Ćrle is too busy eating cheese, he asked you to designate it instead

    Input:
    5 10
    3 2 2 1 4
    3 2 2 7 4
    8 2 2 1 3
    8 8 9 9 9
    8 8 1 5 1
    Output: 5
    explain output: good parts of farm are those who contains numbers 2, 4, 5, 7 and 9

    CAN SOMEONE DO THIS IN C?


  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Please read the "Forum Rules FAQ's"! YOU need to try to create the program yourself, then we can give comments and advice.

  3. #3
    Registered User
    Join Date
    Jan 2019
    Posts
    3
    I was trying for 3-4 hours with my friend and we cant do it

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    You need to post the code you have so far so we can compile, and test, then give advice.

    NO ONE here is going to write the program for you!

  5. #5
    Registered User
    Join Date
    Jan 2019
    Posts
    3
    Problem is that i cant find solution for both programs, can someone give me hint or tell me way of thinking

  6. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Aparently we cannot since you will not cooperate with us. Please read my first reply and the link I put in the message.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Step 1 solve the problem with pencil and paper before you try to code the solution.

    I have no idea how to solve the first problem because I fail to understand it.

    The second I can solve using pencil and paper; but, I see no simple solution just a brute force type of solution.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Problem 1 reworded (I think) :

    You are given a grid of bools of N rows by M columns, initially false.
    For each row you are given a number A and you can either set the first A columns or the last M-A columns to true.
    After that, multiply the number of false positions by the number of true positions in each column and sum them.
    What is the minimum possible sum?

    Input:
    N M
    A1
    A2
    ...
    AN

    Example 1:
    2 3
    1
    2

    F T T
    F F T

    0 * 1 + 1 * 1 + 1 * 0 = 1

    Example 2:
    4 4
    2
    1
    4
    1

    T T F F
    T F F F
    F F F F
    T F F F

    1 * 3 + 3 * 1 + 4 * 0 + 4 * 0 = 6

    There's only 2 posibilities to try for each row, so the brute force solution needs to test 2 pow N possibilities.
    Last edited by john.c; 01-26-2019 at 05:18 PM.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can you solve this per
    By nkrao123@gmail. in forum C Programming
    Replies: 4
    Last Post: 11-16-2009, 12:50 AM
  2. Replies: 1
    Last Post: 11-09-2009, 07:03 AM
  3. Please Solve the two C programs..
    By psaha in forum C Programming
    Replies: 7
    Last Post: 10-25-2009, 06:50 AM
  4. how to solve this bug??
    By transgalactic2 in forum C Programming
    Replies: 31
    Last Post: 10-07-2008, 10:26 PM
  5. Programs opening programs
    By LinuxPLC in forum C Programming
    Replies: 1
    Last Post: 11-21-2002, 12:50 PM

Tags for this Thread