Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6795903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:24:10+00:00 2026-05-26T18:24:10+00:00

Any algorithms that would help? I’m gunning at something to help me nail this

  • 0

Any algorithms that would help? I’m gunning at something to help me nail this problem:

Hearing that the latest fashion trend was cows with two spots on their hides, Farmer John has purchased an entire herd of two-spot cows. Unfortunately, fashion trends tend to change quickly, and the most popular current fashion is cows with only one spot! FJ wants to make his herd more fashionable by painting each of his cows in such a way that merges their two spots into one. The hide of a cow is represented by an N by M (1 <= N,M <= 50) grid of characters like this:

................ 
..XXXX....XXX... 
...XXXX....XX... 
.XXXX......XXX.. 
........XXXXX... 
.........XXX....

Here, each ‘X’ denotes part of a spot. Two ‘X’s belong to the same spot if they are vertically or horizontally adjacent (diagonally adjacent does not count), so the figure above has exactly two spots. All of the cows in FJ’s herd have exactly two spots. FJ wants to use as little paint as possible to merge the two spots into one. In the example above, he can do this by painting only three additional characters with ‘X’s (the new characters are marked with ‘*’s below to make them easier to see).

................ 
..XXXX....XXX... 
...XXXX*...XX... 
.XXXX..**..XXX.. 
........XXXXX... 
.........XXX.... 

Please help FJ determine the minimum number of new ‘X’s he must paint in order to merge two spots into one large spot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:24:10+00:00Added an answer on May 26, 2026 at 6:24 pm

    This would be just a simple breadth-first search (or wave algorithm as it’s sometimes called).

    You start at one of the spots, putting each X position in the queue. For each position, you maintain a neighboring position which lies on a path from the spot to the position. In each step, you get a position from the queue, put each neighbor to the queue, change their “neighbor” data, rinse and repeat. On top of that, you make sure you don’t touch any place that has its neighbor recorded.

    In the end, you reach the second spot, end the neighbor data tell you where is the shortest path connecting the two.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any algorithms that can help with hierarchical clustering? Google's map-reduce has only
do you know any good algorithms that match two strings and then return a
Are there any algorithms or tools that can increase the resolution of an image
I am wondering if there are any well-known algorithms that I should be aware
Are there any good references for synchronisation algorithms? I'm interested in algorithms that synchronize
Are there any compression algorithms -- lossy or lossless -- that have been specifically
I was wondering if someone could help me get pointers to solve this problem.
Mathematics/algorithms was never my strong point (!) so requesting help on this one. What
I am studying membership algorithms and I am working on this particular problem which
Is there any fast algorithm that allows to compare two files (for verification purpose)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.