小编Mat*_*att的帖子

Golang如何在Go中读取输入文件名

我想运行我的go文件,当我输入go run命令时input.txt,我的go程序将读取input.txt文件,即:

go run goFile.go input.txt
Run Code Online (Sandbox Code Playgroud)

我不想放入input.txt我的goFile.go代码,因为我的go文件不应该只在任何输入名称上运行input.txt.

我尝试ioutil.ReadAll(os.Stdin)但我需要改变我的命令

go run goFile.go < input.txt
Run Code Online (Sandbox Code Playgroud)

我只用包fmt,os,bufioio/ioutil.没有任何其他包装可以做到吗?

file go readfile

7
推荐指数
1
解决办法
5828
查看次数

关于NP-hard和NP-Complete在旅行商问题上的困惑

旅行推销员优化(TSP-OPT)是NP难问题,旅行推销员搜索(TSP)是NP完全的.但是,TSP-OPT可以简化为TSP,因为如果TSP可以在多项式时间内求解,那么TSP-OPT(1)也可以.我认为A要降低到B,B必须要比A更难.如我在下面的参考文献中所见,TSP-OPT可以降低到TSP.TSP-OPT应该比TSP更难.我很迷惑...

参考文献:(1)算法,Dasgupta,Papadimitriou,Vazirani练习8.1 http://algorithmics.lsi.upc.edu/docs/Dasgupta-Papadimitriou-Vazirani.pdf https://cseweb.ucsd.edu/classes/sp08/cse101 /hw/hw6soln.pdf

http://cs170.org/assets/disc/dis10-sol.pdf

complexity-theory time-complexity non-deterministic computation-theory np

6
推荐指数
2
解决办法
1157
查看次数

Clingo答案集编程新手

我得到了以下答案集编程问题,但不确定我的答案是否正确:

  • A(X)通常是E(X)
  • U(X)通常不是E(X)
  • G(X)通常是E(X)
  • 每个G(X)是U(X)
  • U(X)通常是A(X)
  • G(T1)
  • G(t2)而不是E(t2)
  • U(T3)

以下是我的Clingo代码:

  g(t1).
g(t2).
-e(t2). 
u(t3).
e(X) :- a(X), not -e(X).
-e(X) :- u(X), not e(X).
e(X) :- g(X), not -e(X).
u(X) :- g(X).
a(X) :- u(X), not -a(X).
Run Code Online (Sandbox Code Playgroud)

clingo 0 pm.lp是:

    Reading from pm.lp
pm.lp:9:15-24: info: atom does not occur in any rule head:
  not (-a(X))

Solving...
Answer: 1
g(t1) g(t2) u(t3) -e(t2) u(t1) u(t2) a(t3) a(t1) a(t2) e(t3) e(t1)
Answer: 2
g(t1) g(t2) u(t3) -e(t2) u(t1) u(t2) a(t3) a(t1) a(t2) …
Run Code Online (Sandbox Code Playgroud)

answer-set-programming clingo

5
推荐指数
0
解决办法
604
查看次数