int DFS(a, b,c,d)
{
first=a+b;
second=c+d;
return(first,second);
}
solution, cost_limit = DFS(a, b,c,d);
Run Code Online (Sandbox Code Playgroud)
我可以这样做吗?如何?
在上面的代码中,else-if部分给了我错误.else-if的含义是:else如果x的值不在deque中那么......
#include <iostream>
#include <ctime>
#include <stack>
#include <deque>
#include <algorithm>
deque<char> visited;
char x;
if (x==target[4][4])
{
visited.push_back(x);
return (visited);
}
else if (!(find(visited.begin(), visited.end(), x)))
{
visited.push_back(x);
}
Run Code Online (Sandbox Code Playgroud)
错误:没有操作员"!" 匹配这些操作数
我如何在文本框或输出中打印程序运行的时间?
我希望它显示为for循环,以获得每个for循环所需的时间.
我必须在运行15-puzzle问题时对IDA*(迭代加深A星)算法进行可视化.确切地说,我需要想象树和拼图.
我需要实现3件事:
1)IDA*代码.
2)之后,IDA*与问题相关(15-puzzle).
3)然后,我需要可视化算法的树.
但我相信以前有人必须为运行15-puzzle问题的IDA*实施代码.我需要你的帮助来找到这个源代码,这样我就不会花2个月的时间编写之前由其他人编写的代码,这样我就有时间专注于可视化.
我知道一些C,C++和C#.
我需要一个简单的源代码,我会理解,在这个源代码中你输入一个表作为拼图,它会将你作为一个带有解决难题的表格返回.
其次,您建议我使用上述3中的哪种编程语言进行可视化?
我找到了一些实现:
C++中的A*,我需要IDA*
IDA*在pheudocode link1 link2 link3中
解决滑动拼图的A*和IDA*(这个使用未定义的模板)
我一直在和我一起工作<map>,在那里我宣布了一张地图
map <int, vector<int> > tree;
Run Code Online (Sandbox Code Playgroud)
我正在尝试为它赋值.我的目标是将多个值作为其键的元素.像这样的东西:
0=null
1=>0
2=>1,0
3=>2,1,0
4=>3,2,1,0
5=>0
Run Code Online (Sandbox Code Playgroud)
我试图像这样分配到地图但它不起作用.
tree[3]=vector<int>(2,1,0);
Run Code Online (Sandbox Code Playgroud)
你能弄清楚问题出在哪里,或者我如何创建一个兼容Python字典的函数?
编辑:<map>
以上2种分配工作方式.
编辑2:我没有使用 <map>
我有兴趣将这个Python代码移植到C++.作为港口的一部分,我用std::stack从<stack>头.如何确定某个字符是否包含在某个字符中stack<char>?例如:
std::stack<char> myStack
if (!('y' is included in myStack)) // I know that this is wrong
{
}
Run Code Online (Sandbox Code Playgroud) 我无法在python中找到具体的注释,例如<!-- why -->.我的主要原因是找到2条具体评论中的所有链接.像解析器一样的东西.我试过这个Beautifulsoup:
import urllib
over=urlopen("www.gamespot.com").read()
soup = BeautifulSoup(over)
print soup.find("<!--why-->")
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我想我可能不得不使用regex而不是Beautifulsoup.
请帮忙.
示例:我们有像这样的HTML代码
<!--why-->
www.godaddy.com
<p> nice one</p>
www.wwf.com
<!-- why not-->
Run Code Online (Sandbox Code Playgroud)
编辑:在2条评论之间,可能存在其他东西,如标签.
我需要存储所有链接.
我有一个名为mylist的列表.如果我输入print mylist我的程序,我可以打印我的列表并查看项目.然后我将列表项转移到堆队列中:
myheap=heapq.heapify(mylist)
print myheap
Run Code Online (Sandbox Code Playgroud)
它打印None.怎么了?
我有这部分代码,它接受一个文件并将其放入ArrayList.将要输入的文件是CSV(CSV我使用的当前第一行的标题,所以我不需要该行),第二行必须放入ArrayList.
我使用ArrayList是因为文件可以是动态的,所以我不确定第二行的长度是多少.我测试了(使用在第二行上有7个逗号分隔值的文件)此代码,并打印出ArrayList有长度(fileList.Count)= 1.
怎么了 ?
ArrayList fileList2 = new ArrayList();
private void button3_Click(object sender, EventArgs e)
{
string filename = "";
DialogResult result = openFileDialog2.ShowDialog();
if (result == DialogResult.OK)
{
filename = openFileDialog2.FileName;
textBox3.Text = filename;
string line2;
System.IO.StreamReader file2 = new System.IO.StreamReader(textBox3.Text); //reads file from textbox
stringforData = file2.ReadLine(); // this reads the first line that I dont need
while ((line2 = file2.ReadLine()) != null) …Run Code Online (Sandbox Code Playgroud) 我写这个没有包括它成功运行.是srand和random_shufflestd库中的?怪不是吗?
#include <array>
#include <time.h>
#include <vector>
using namespace std;
int main()
{
vector<int> myvector;
srand((unsigned)time(NULL));
for (int i=0; i<10; ++i)
{myvector.push_back(i);}
random_shuffle ( myvector.begin(), myvector.end() );
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将字符串打印到文件中.我做错了什么,它总是给我一个NullPointException?我相信我的异常会抓住某些东西或需要参数,我不会输入它.但是哪里?
我已经写了这个包含main函数的代码.
编辑:从底部第二行获取错误some.items[0]="Testing One!";.
import java.io.*;
public class StringPrinter {
public String[] items;
public File file;
public StringPrinter(String fileName){
file = new File(fileName);}
public void toFile(){
try{
PrintWriter pw = new PrintWriter(new FileWriter(file, false));
for (String st:items){
pw.println(st);
}
}
catch(Exception exception){}
}
public static void main(String args[]){
StringPrinter some=new StringPrinter("Workyou.txt");
some.items[0]="Testing One!";
some.items[1]="Testing Two!";
some.toFile();
}
}
Run Code Online (Sandbox Code Playgroud) unix打印具有多于2个项目的文件行的命令是什么?例如,每行中包含由tab标记的项目的文件.
dog elephant
fox dog monkey
bear bird
fish puppy
Run Code Online (Sandbox Code Playgroud)
在上面的文件中输出将是fox dog monkey.
在python中它将是:
if len(line)> 2:
print line
Run Code Online (Sandbox Code Playgroud) 我如何随机制作4x4 array<array<int,4>,4>?这2D阵列的每个元素应该是唯一的号码从区间从0到15(含).
例:
6 7 5 4
10 11 12 15
1 3 2 8
9 14 0 13
Run Code Online (Sandbox Code Playgroud)