本文介绍了像素填充工具这是一个有趣的难题,请帮助我"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拼图说明

接受代码的完整列表在《代码提交指南》中.

白天,您在一家飞速发展的设计公司工作,而到了晚上,您以 有价值的程序员的身份向互联网兜售,这些程序员倾向于为开源做贡献.没有人知道您的双重身份,同事有时会挑战您解决随机问题.

当您在午餐时间聊天时,一位同事提到他发现了大量的黑白数码照片.他问您仅通过使用图像处理程序中的像素填充工具,将所有这些照片变成白色将需要单击几下.像素填充工具是一项简洁的功能,只需单击鼠标即可将黑色像素的区域变成白色像素.

您内在的 智能程序员开始思考,您确定可以以编程方式找出答案...

为了简单起见,黑白图像是由X * Y值组成的矩阵.
0代表黑色像素,而1代表白色像素.

以下是一个具有一些白色和一些黑色像素的7x5图像:

10001
10100
00000
00000
00111
00100
00100

只需单击一下,像素填充工具就会将每个黑色像素变成白色像素,直到从上一个像素无法到达黑色像素为止.一个像素通过多达八种方式与另一个像素相连:北,南,东,西和四个对角线.

只需单击两次,即可用白色像素填充上面的图像:第一次单击:

11111
11111
11111
11111
11111
11100
11100

第二次点击:

11111
11111
11111
11111
11111
11111
11111

Puzzle Description

A complete list of accepted languages is in the Code Submission Guidelines.

During the day you work at a high flying design company, but at night you troll the internet as a valuable programmer that tends to contribute to open source. No one knows your dual identity and once in a while a coworker will challenge you to solve a random problem.

As you chat at lunch, a coworker mentions he found a large number of digital black and white photos. He asks you how many clicks it would take to turn all these photos white by only using the pixel fill tool in your image manipulation program. The pixel fill tool is a neat feature that turns an area of black pixels into white pixels with just the click of a mouse.

The smart programmer you are inside starts to think, and you determine you can programmatically figure out the answer...

For the sake of simplicity, a black and white image is a matrix composed of X * Y values.
A 0 represents a black pixel and a 1 represents a white pixel.

The following is a 7x5 image with some white and some black pixels:

10001
10100
00000
00000
00111
00100
00100

With one click, the pixel fill tool turns each black pixel into a white one until there isn''t a black pixel that can be reached from the previous pixel. A pixel is connected with another one in up to eight ways: north, south, east, west and the four diagonals.

The image above can be filled with whites pixel with just two clicks: First click:

11111
11111
11111
11111
11111
11100
11100

Second click:

11111
11111
11111
11111
11111
11111
11111

推荐答案



0010000100
1110000111
0000000000
0000000000
1110000111
0010000100

在这里,您首先要对中间像素进行白色处理,然后留下四个黑角.黑色居中,产生完全黑色的图像.最后又变白了.

与使用第一种策略所需的5次运行相比,这将进行3次运行.

同时处理并采取更快的处理方法.

哦,我可以想到组合起来最快的星座.

Here, you would first white the middle pixel, leaving four black corners. The black the middle, resulting in a completely black image. And finally white again.

That would be 3 runs compared to the 5 that would be necessary using the first strategy.

Process both and take the faster one.

Oh, and I can think of constellations where a combination would be fastest.


这篇关于像素填充工具这是一个有趣的难题,请帮助我"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 15:00