小编Jas*_*son的帖子

git two破折号表示没有更多选项

我正在学习try git by code school,并且单元1.17撤消它使用命令行

git checkout -- octocat.txt
Run Code Online (Sandbox Code Playgroud)

然后octocat.txt是一个文件,它解释了两条虚线

它只是承诺在' - '之后没有更多选项的命令行.这样,如果你碰巧有一个名为octocat.txt的分支,它仍然会恢复文件,而不是切换到同名的分支.

但我无法理解的是,没有选择意味着什么呢?并且由于之后没有选项,为什么它可以通过文件与分支区分?

git version-control github

14
推荐指数
1
解决办法
1918
查看次数

如何将十进制基数(10)转换为负基数(-2)?

我想写一个程序,从十进制转换为否定.

我无法弄清楚如何从十进制转换为否定.

我不知道如何找到规则及其工作原理.

例: 7(base10)-->11011(base-2)

我才知道7 = (-2)^0*1 + (-2)^1*1 + (-2)^2*0 + (-2)^3*1 + (-2)^4*1.

algorithm base-conversion base

10
推荐指数
1
解决办法
9505
查看次数

删除两个元素,将数组在O(n)中均匀分割为三个部分

我遇到一个问题,让你在数组中删除两个元素,使三部分的总和相等.

  Ex:
  1 2 4 3 5 2 1
  After I drop the 4 and 5, it becomes 1, 2 | 3 | 2, 1
Run Code Online (Sandbox Code Playgroud)

约束:

  1.Numbers are all integer > 0

  2.Drop two elements in the array, so the three splitted subarrays will have same subarray sum.
Run Code Online (Sandbox Code Playgroud)

我已经通过使用两遍算法尝试了如下

第一遍:O(n)计算左边的累计和,这样我就可以轻松得到范围和.

第二遍:O(n ^ 2)使用嵌套循环来获取子数组的开始和结束索引.然后,计算左,中,右和.

// 1.get accumulated sum map
int[] sumMap = new int[A.length];
int sum = 0;
for(int i = 0; i < A.length; i ++) {
    sum += A[i]; …
Run Code Online (Sandbox Code Playgroud)

java algorithm

7
推荐指数
2
解决办法
1500
查看次数

在大矩阵中找到矩阵

我有一个非常大的n*m矩阵S.我想有效地确定F内部是否存在子矩阵S.大矩阵S的大小可以大到500*500.

澄清一下,请考虑以下事项:

S = 1 2 3 
    4 5 6
    7 8 9

F1 = 2 3 
     5 6

F2 = 1 2 
     4 6
Run Code Online (Sandbox Code Playgroud)

在这种情况下:

  • F1 在里面 S
  • F2 不在里面 S

矩阵中的每个元素都是32-bit整数.我只能想到使用蛮力方法来查找是否F是子矩阵S.我用谷歌搜索找到一个有效的算法,但我找不到任何东西.

是否有一些算法或原则可以更快地完成它?(或者可能是一些优化蛮力方法的方法?)

PS统计数据

A total of 8 S
On average, each S will be matched against about 44 F.
The probability of success match (i.e. F appears in a S) …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm

6
推荐指数
1
解决办法
8039
查看次数

return类型是类中的变量

我正在寻找C++参考,我看到了

template <size_t I, class... Types>
typename tuple_element< I, tuple<Types...> >::type const& get(const tuple<Types...>& tpl) noexcept;
Run Code Online (Sandbox Code Playgroud)

而我无法理解的是返回类型,typename tuple_element< I, tuple<Types...> >::type const&意味着什么?

我的交互是它返回一个常规类型的const引用tuple_element::type,但我认为这tuple_element::type就像下面

Class A{
  public:
      int B;
}
A::B = .........;
Run Code Online (Sandbox Code Playgroud)

但为什么它可以用作一种类型?我不明白.

c++

6
推荐指数
1
解决办法
234
查看次数

总是阻止@(*)表示?

我有谷歌,但仍然了解它.如果我写下面的代码:

module POLY(CLK,RESET_n,IN_VALID,IN,OUT_VALID,OUT);

input         CLK,RESET_n,IN_VALID;
input  [ 3:0] IN;
output        OUT_VALID;
output [12:0] OUT;
Run Code Online (Sandbox Code Playgroud)

然后使用它.

always @(*)
begin
.........
end
Run Code Online (Sandbox Code Playgroud)

1.是否意味着input CLK,RESET_n,IN_VALID;input [ 3:0] IN;将触发始终阻止或仅在块中使用的输入将触发始终阻止?

2.但它不会写posedge或negedge,所以两个边缘都会触发始终阻塞?

Thx提前.

verilog

5
推荐指数
1
解决办法
2万
查看次数

带有查找表的霍夫曼代码

我已经阅读了 Internet 上的一篇文章,并且知道从根遍历进行解码的自然方式,但我想使用查找表更快地进行解码。

看完了,还是拿不到分。

前任:

输入:“abcdaabaaabaaa”
代码数据
0个
10个
110 摄氏度
111天

文章说,由于长度可变,它通过取一个最大代码长度的字符串来确定长度并将其用作索引。

输出:“010110111001000010000”
索引 索引(二进制) 需要的代码位
0 000 1
1 001 一 1
2 010 一 1
3 011 一 1
4 100 b 2
5 101 b 2
6 110 c 3
7 111 d 3

我的问题是:

  1. 这是什么意思due to variable length, it determine the length by taking a bit of string of max code length?如何确定长度?

  2. 如何生成查找表以及如何使用它?背后的算法是什么?

c++

4
推荐指数
1
解决办法
2949
查看次数

检测HashMap包含或不包含相同List的更好方法

我有一个List将随时间更改的值,我想将其与时间值一起存储,并检查是否List再次出现该值。

例如:

[1, 2, 3] is same as [1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

我认为既然List<Integer>是通过参考值传递的,所以我认为应该将键字符串化以使用。

例如:

Map<String, Integer> = new HashMap<>()
(key:"stringified key", value: .....)
Run Code Online (Sandbox Code Playgroud)

但是我发现它Map<List<Integer>, Integer> map = new HashMap<>()也可以工作,但是我不知道它为什么起作用,因为无论列表中的值发生了什么变化,键都应该引用相同的列表。

例如:

(key:[reference to key], value: .....)
List<Integer> testList = new ArrayList<>();
testList.add(0);
map.put(testList, 0);
testList.set(0, 1);
if(map.containsKey(testList))System.out.println("duplicate");
else System.out.println("unique");
Run Code Online (Sandbox Code Playgroud)

上面的结果将打印“唯一”,但我认为应该打印“重复”。为什么以上结果显示了这一点?

java list hashmap

3
推荐指数
1
解决办法
65
查看次数

结束的原因随身携带

我知道如果最高位有进位,则r-base数的r-1补码应该以进位结束.

但我无法弄清楚为什么要这样做.

我只能想到它可能是关于零的两个表示的原因.

例如:

 1 1 1 0    (-1)
 0 1 0 1    (+5)  
 ===============
10 0 1 1  =====>(0 1 0 0)
I just can explain it from the result that because its sum is positive, and 1's complement has two representations, so it should add one.
Run Code Online (Sandbox Code Playgroud)

例如:

 1 1 1 0    (-1)
 1 0 1 0    (-5)  
 ===============
11 0 1 1  =====>(1 0 0 1)
And I cannot explain it why should add one.
Run Code Online (Sandbox Code Playgroud)

结束携带的真正原因是什么?

感谢你阅读它.

computer-science

2
推荐指数
1
解决办法
4473
查看次数

通过哈夫曼表重建哈夫曼树

我编写了一个程序将一篇文章编码为霍夫曼代码并输出一个代码表。

时:000
日:1011
电子:100
左:11
时:01
回复:1010
字:001
总位数:27
编码代码:000100111101001011010111011

我想编写一个程序,将文件作为输入并对其进行解码。

但我不知道如何重建它。

我的问题是如何重建哈夫曼树?

c++ huffman-code

2
推荐指数
1
解决办法
3532
查看次数

printf如何知道在符号扩展后要打印的内容

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv){
    char i = -128; 
    int j = i; 
    printf("%d %u\n", j, j); 
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

结果是 -128 4294967168

我的想法是什么

i: 10000000 
Run Code Online (Sandbox Code Playgroud)

在赋值运算符之后,执行符号扩展

j: 11111111 11111111 11111111 10000000 
Run Code Online (Sandbox Code Playgroud)

我想问的是如何printf("%d",j)知道打印-128只是使用

最后一个字节?这个怎么运作?

谢谢!

c

0
推荐指数
1
解决办法
343
查看次数

访问范围从from但未定义

我写的是这样的:

<form>
    <input>text</input>
    <div><span id="test">text</span></div>
.................
<button onclick="submitStudnetForm(this);"></button>
</form>

function submitStudnetForm(form){
    alert(form['test']);
}
Run Code Online (Sandbox Code Playgroud)

但它返回undefined,我不在哪里错了?

Thx提前.

javascript html5 dom

0
推荐指数
1
解决办法
46
查看次数

矢量坏投掷alloc expetion甚至不访问任何元素

我写下面的代码

#include <vector>
#include <cmath>
#include <cfloat>
#include <iostream>
#include <algorithm>
using namespace std;



vector< vector<double> > merge_sort(vector< vector<double> >& source, vector< vector<double> >& result){





}

int main(){

       vector < vector<double> >test;
       vector < vector<double> >temp;

    merge_sort(test, temp);

}
Run Code Online (Sandbox Code Playgroud)

而我的例外,该程序关闭,我只是得到错误的分配预算,我不知道为什么,我甚至没有访问任何元素.

请告诉我如何解决它.

Thx提前.

c++

-2
推荐指数
1
解决办法
80
查看次数