• You control an animated frog that can walk and hop, in both forward and backward directions. The frog stands in a space between an otherwise a contiguous line of tiles. Each tile is painted black on ...
• You control an animated frog that can walk and hop, in both forward and backward directions. The frog stands in a space between an otherwise a contiguous line of tiles. Each tile is painted black on ...
• Problem Description KERMIT THE FROG is a classic video game with a simple control and objective but requires a good deal of thinking. ...You control an animated frog that can walk and hop, in both fo

Problem Description

KERMIT THE FROG is a classic video game with a simple control and objective but requires a good deal of thinking.
You control an animated frog that can walk and hop, in both forward and backward directions. The frog stands in a space between an otherwise a contiguous line of tiles. Each tile is painted black on one side, and white on the other. The frog can walk (forward,
or backward) over an adjacent tile (in front or behind him.)
When the frog walks over a tile, the tile slides to the space where the frog was standing. For example, in the adjacent figure, the frog has two tiles behind him, and three in front. We’ll use the notation BWFBBW to refer to this situation where F refers to
the space (where the frog is standing,) B is a tile with its black face showing, while W is a tile with its white face showing. The forward direction is from left to right. If the frog were to walk forward, the resulting situation is BWBFBW. Similar behavior
when the frog walks backward, the tile behind the frog slides to where the frog was standing. The frog can also hop over the tiles. The frog can hop over an adjacent tile landing on the tile next to it. For example, if the frog was to hop backward, it would
land on the first (left-most) tile, and the tile would jump to the space where the frog was standing. In addition, the tile would flip sides. For example, hopping backward in the figure would result in the situation: FWWBBW. We challenge you to write a program
to determine the minimum number of moves (walks or hops) to transform one tile configuration into another.

Input

Your program will be tested on one or more test cases. Each test case is specified on a single line that specifies string S representing the initial tile arrangement. S is a non-empty string and no longer than 100 characters and is made of the letters ’B’,
’W’, and exactly one ’F’. The last line of the input file has one or more ’-’ (minus) characters.

Output

For each test case, print the following line:
k. M
Where k is the test case number (starting at one,) and M is the minimum number of moves needed to transform the given arrangement to an arrangement that has no white tile(s) between any of its black tiles . The frog can be anywhere. M is -1 if the problem cannot
be solved in less than 10 moves.
Note: There is a blank space before M.

Sample Input

WWBBFBW
WWFBWBW
FWBBWBW
---

Sample Output

1. 0
2. 1
3. 2
bfs，注意判断结束状态。#include<map>
#include<queue>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define make(x,y) make_pair(x,y)
#define pii pair<bitset<N>,pair<int,int> >
#define fi first
#define se second
#define rep(i,j,k) for (int i=j;i<=k;i++)
const int N=105;
int T=0,y,len;
char s[N];
bitset<N> x;

struct point
{
bitset<N> a;
int wz;
point(bitset<N> a,int wz):a(a),wz(wz){}
bool operator<(const point b)const
{
rep(i,0,N-1)
{
if (a[i]==b.a[i]) continue;
else return a[i]<b.a[i];
}
return wz<b.wz;
}
};

map<point,bool> M;

bool check(bitset<N> x,int y)
{
int tot=x.count();
for(int i=0;i<len;i++)
{
if (!x[i]) continue;
if (i<y)
{
rep(j,i,i+tot-2) if (!x[j]) return false;
return x[i+tot-1]||y>=i+tot;
}
if (i==y) tot--;
if (i>y)
{
rep(j,i,i+tot-1) if (!x[j]) return false;
return true;
}
}
return true;
}

int bfs()
{
queue<pii> p;
p.push(make(x,make(0,y)));
if (check(x,y)) return 0;
while (!p.empty())
{
pii q=p.front(); p.pop();
if (q.se.first==9) return -1;
int step=q.se.fi,now=q.se.se;
if (now>0)
{
bitset<N> t=q.fi;
t[now]=t[now-1];
t[now-1]=1;
if (!M[point(t,now-1)])
{
if (check(t,now-1)) return step+1;
M[point(t,now-1)]=true;
p.push(make(t,make(step+1,now-1)));
}
}
if (now+1<len)
{
bitset<N> t=q.fi;
t[now]=t[now+1];
t[now+1]=1;
if (!M[point(t,now+1)])
{
if (check(t,now+1)) return step+1;
M[point(t,now+1)]=true;
p.push(make(t,make(step+1,now+1)));
}
}
if (now>1)
{
bitset<N> t=q.fi;
t[now]=t[now-2];
t[now-2]=1;
t.flip(now);
if (!M[point(t,now-2)])
{
if (check(t,now-2)) return step+1;
M[point(t,now-2)]=true;
p.push(make(t,make(step+1,now-2)));
}
}
if (now+2<len)
{
bitset<N> t=q.fi;
t[now]=t[now+2];
t[now+2]=1;
t.flip(now);
if (!M[point(t,now+2)])
{
if (check(t,now+2)) return step+1;
M[point(t,now+2)]=true;
p.push(make(t,make(step+1,now+2)));
}
}
}
return -1;
}

int main()
{
while (~scanf("%s",s),s[0]!='-')
{
x.reset();
M.clear();
len=strlen(s);
for (int i=0;s[i];i++)
{
x[i]=s[i]!='W';
if (s[i]=='F') y=i;
}
printf("%d. %d\n",++T,bfs());
}
return 0;
}


展开全文
• You control an animated frog that can walk and hop, in both forward and backward directions. The frog stands in a space between an otherwise a contiguous line of tiles. Each tile is painted black on ...
• <p>In case the <code>terraform</code> process executed by Atlantis crashes during a <code>plan, Atlantis remains on an infinite pending state on VCS. <p><img alt="Screenshot 2020-06-16 at 10 56 29" ...
• 1. Basic Selectors ...$('p')—Accesses all the paragraph elements in the HTML file$('div')—Accesses all the div elements in the HTML file $('#A')—Accesses all the HTML elements wit... 1. Basic Selectors$('p')—Accesses all the paragraph elements in the HTML file

$('div')—Accesses all the div elements in the HTML file$('#A')—Accesses all the HTML elements with id=A

$('.b')—Accesses all the HTML elements with class=b 2. Applying CSS to Elements$('div').addClass('highlight');

3. Some basic selection APIs

// select all the elements that contain the text Life
$('span:contains(Life)').addClass('highlight');$('div:odd').addClass('highlight');
$('div:even').addClass('boundary');$('p:eq(1)').addClass('linkstyle');

4. Obtaining the HTML of an Element

alert($('p').html()); 5. Changing the Content of a DOM Node$('#textId').text('some text content');

$('p').html('<b>We can create Rich Internet Applications </b><br/>by making AJAX requests'); 6. Creating a DOM Node on the Fly 1) Inserts the specified content at the beginning of the selected element and returns a jQuery object$('p').prepend('<h2> Power of selectors </h2>');

转载于:https://www.cnblogs.com/davidgu/p/3349501.html
展开全文
• <p>One option is to add a command like <code>terragrunt spin-up</code> which could find all the Terraform modules in the folder structure (based on the presence of a <code>.tf</code> files), parse the...
• 利用 os.walk()函数遍历当前文件夹下的所有文件和文件夹得到名称 再利用 正则 与数据库对比，从而得到缺少哪个文件 不仅可以在班委收集数据统计，还可以用于文件对比方面（需改动代码） 使用教程：将脚本放置你所要...
• # 列出文件夹内所有代码 def list_dictionary_codes(root_dir): paths_list = [] ... for parent, dirNames, fileNames in os.walk(root_dir): for name in fileNames: ext = ['.h', '.m', '.xib', '....
对比度与亮度调整方法1
对图片对比度和亮度的调整一般通过下面公式计算：
$g(x,y) = a*f(x,y)+b$

$f(x,y)$ 代表源图像 x行，y列的像素点的c通道的数值
$g(x,y)$ 代表目标图像x行，y列的像素点的c通道的数值
$a$ 参数（a>0）表示放大的倍数（一般在0.0~3.0之间）
$b$ 参数一般称为偏置，用来调节亮度

import  cv2

cv2.imshow('original_img',img)
rows,cols,channels=img.shape
dst=img.copy()

a=0.5
b=80
for i in range(rows):
for j in range(cols):
for c in range(3):
color=img[i,j][c]*a+b
if color>255:           # 防止像素值越界（0~255）
dst[i,j][c]=255
elif color<0:           # 防止像素值越界（0~255）
dst[i,j][c]=0

cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()


对比度与亮度调整方法2
"""
函数详解：
double_alpha,
InputArray_src2,
double_beta,
double_gamma,
OutputArray_dst,
int_dtype=-1
);
"""

一共有七个参数：前4个是两张要合成的图片及它们所占比例，
第5个double gamma起微调作用，
第6个OutputArray dst是合成后的图片，
第7个输出的图片的类型（可选参数，默认-1）

有公式得出两个图片加成输出的图片为：dst = src1 * alpha+src2 * beta + gamma
def contrast_img(img1, c, b):  # 亮度就是每个像素所有通道都加上b
rows, cols, channels = img1.shape

# 新建全零(黑色)图片数组:np.zeros(img1.shape, dtype=uint8)
blank = np.zeros([rows, cols, channels], img1.dtype)
dst = cv2.addWeighted(img1, c, blank, 1-c, b)
cv2.imshow('original_img', img)
cv2.imshow("contrast_img", dst)

contrast_img(img, 1.3, 3)
cv2.waitKey(0)
cv2.destroyAllWindows()



展开全文
• Here is a brief walk-through of the chapters: • Chapter 1: Thinking Functionally Our generation of programmers has been raised with object-oriented programming ideas. This initial chapter is ...
• 使用Python3.X 批量将文件夹中的所有docx文档转为PDF 代码示例： from win32...import os def get_docx(input_Docxs): DocxPaths = [] for root,dirs,filenames in os.walk(input_Docxs): for fil...
使用Python3.X 批量将文件夹中的所有docx文档转为PDF
代码示例：
以下处理的.docx文件由这篇文章代码产生：https://blog.csdn.net/wsp_1138886114/article/details/96508728
from win32com import client as wc
import os

def get_docx(input_Docxs):
DocxPaths = []
for root,dirs,filenames in os.walk(input_Docxs):
for filename in filenames:
if filename.endswith(('.docx','.doc')):
DocxPaths.append(root+'/'+filename)
return DocxPaths

def docx2pdf(input_Docxs,pdf_path):
DocxPaths = get_docx(input_Docxs)
print('DocxPaths',DocxPaths)
word = wc.Dispatch('Word.Application')
word.Visible = 0

for docx_path in DocxPaths:
pdf_name = pdf_path+'/'+docx_path.split('/')[-1][:-5]+'.pdf'
try:
doc = word.Documents.Open(docx_path)
doc.SaveAs(pdf_name, 17)  # 直接保存为PDF文件
doc.Close()
except:
print('%s 转换失败' % docx_path)
word.Quit()

if __name__ == '__main__':
input_Docxs = 'D:\\python_script\\office_docx_pdf'
pdf_path = 'D:\\python_script\\office_docx_pdf'
docx2pdf(input_Docxs, pdf_path)

使用以下写法，代码报错，暂时未找到原因，望各位看官不吝赐教
from win32com.client import Dispatch, constants, gencache, DispatchEx
import os

def get_docx(input_Docxs):
DocxPaths = []
for root, dirs, filenames in os.walk(input_Docxs):
for filename in filenames:
if filename.endswith(('.docx', '.doc')):
DocxPaths.append(root + '/' + filename)
return DocxPaths

def docx2pdf(input_Docxs, pdf_path):
DocxPaths = get_docx(input_Docxs)

for docx_path in DocxPaths:

gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4)
word = Dispatch('Word.Application')
word.Visible = 0
pdf_name = pdf_path + '/' + docx_path.split('/')[-1][:-4] + '.pdf'

try:
doc.ExportAsFixedFormat(pdf_name, constants.wdExportFormatPDF,
Item=constants.wdExportDocumentWithMarkup,

word.Quit(constants.wdDoNotSaveChanges)
except:
print('%s 转换失败' % docx_path)

if __name__ == '__main__':
input_Docxs = '../office_docx_pdf'
pdf_path = '../office_docx_pdf'
docx2pdf(input_Docxs, pdf_path)

'''
pywintypes.com_error: (-2147352567, '发生意外。', (0, 'Microsoft Word', '很抱歉，找不到您的文件。
该项目是否已移动、重命名或删除?\r(C:\\Users\\XXX\\...\\demo_张三.docx)', 'wdmain11.chm', 24654, -2146823114), None)
'''



展开全文
• Take an Asyncio walkthrough, including a quickstart guide to help you hit the ground looping with event-based programming Learn the difference between Asyncio features for end-user developers and ...
• chr — 返回指定的字符 说明 string chr ( int $ascii ) 返回相对应于 ascii 所指定的单个字符。此函数与 ord() 是互补的。 参数 ascii ...$str = "The string ends in escape: "; \$str .= chr
• Thank you for purchasing or considering the purchase of Windows 7 In Depth. It’s amazing the changes that 20-odd years can bring to a com- puter product such as Windows. When we wrote our first ...
• 1758: Biggest Number Time Limit: 1 Sec Memory Limit: 128 MB [Submit][Status][Web Board] ...You have a maze with obstacles and non-zero digits in it: You can start from any square, walk in...
• Graph Algorithms: Practical Examples in Apache Spark and Neo4j By 作者: Mark Needham – Amy E. Hodler ...Walk through creating an ML workflow for link prediction combining Neo4j and Spark
• <p>The preceding commits were things which were all in the critical path, so for simplicity they are in the same PR. They should each be viewed separately. <p>Would it be a good idea for me to do a ...
• it—in a word: Java. For enterprise developers, Clojure’s Java heritage is a feature; to web developers, it’s a bug. If you come from the web developer world, I’m here to tell you not to be afraid ...
• (require [hy.contrib.walk [*]]) => (let [(get some-dict "some-key") 2] ... (print some-dict)) File "<input>", line 1, column 7 (let [(get some-dict "some-key")...
• 乘法表结果：任务2—查找特定名称文件思路：os.walk()方法os.walk()使用示例：2.查找文件结果：任务3—百度AI开放平台体验感想 任务1—乘法表 要求： 乘法表内容是否正确(30) 指定名称文件是否全部输出(50) 输出形式...
• StackSummary.extract(walk_stack(f), limit=limit) File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/traceback.py", line 358, in extract f.line ...
• 1.统计目录下的文件数量 例如：统计"jpg"格式的照片 import os path = 'H:/TF4/tf4-data-add/' #获取当前路径...for root,dirs,files in os.walk(path): #遍历统计 for each in files: if each.endswith('jpg'): ...
• TECHNIQUE #1: DRESS FOR "THE KILL"—EVERYWHERE Men, this does not mean you have to don ...walk the dog. What it does mean is whenever you step out the door, step out dressed to kill . . . your Quarry.
• 对文件后缀名进行修改 import os def file1_name(file_dir): ''' 批量修改文件后缀名 ... for root, dirs, files in os.walk(file_dir): for file in files: oldname = os.path.splitext(...
• 1 # 查找电脑所有视频 ...2 for cur_dir,dirs,files in os.walk(r'f:'): 3 print('当前正在%s目录下查找'%cur_dir) 4 for f in files:#当前目录下的所有文件 5 if f.endswith('.mp4'): 6 real_path = os.path.j...
• <p>So I want to walk through DID:BTCR from the vantage point of a number of steps that fall into the Integrity/Inspection/Validation/Verification/Confirmation/Revocation spectrum of roles. <p>First, ...
• walkthrough" of relevant code changes using a GitHub code review comment process - [none expected] If any diffs are expected, author must demonstrate they are justified using plots and ...
• Walk into our stores & you'll find some of the best cheeses in the world. Read up on all things cheese including types, cooking with cheese, & more. (7) Gourmet Cheese | Di Bruno Bros. ...