图形互补的这些代码片段有什么区别?
What is the difference between these code snippets of graph complementing?
我使用这个代码片段来获取我的图的补码-
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
{
if(i != j)
{
graph[i][j] = 1 - graph[i][j];
}
}
}
这给出了一个错误的答案。但是当我用下面的代码片段替换它时,它被接受了-
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(graph[i][j] == 1)
graph[i][j] = 0;
else if(i != j)
graph[i][j] = 1;
}
}
我看不出这两者有什么区别
this:
if(i!=j)
{
graph[i][j]= 1-graph[i][j];
}
和下面的不一样:
if(graph[i][j] == 1) graph[i][j] = 0;
else if(i != j) graph[i][j] = 1;
在第一种情况下,你将矩阵修改为除了对角线以外的任何地方都是1-N
给定这个矩阵:
1 1 0
1 1 0
1 1 0
第一个代码会给你:
1 0 0
0 1 0
0 0 0
第二个会给你:
0 0 1
0 0 1
0 0 0
试试这个:
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
if(i != j || graph[i][j] == 1) {
graph[i][j] = 1 - graph[i][j];
}
}
}
您只是没有添加代码graph[i][j] == 1
相关文章:
- 这个带有模板<类 Vector 的C++代码片段有什么问题>
- 这个片段中关于 n 在 pc[i] 中的表示发生了什么
- 只显示片段着色器的最佳方式是什么
- 是什么解释了这个片段中如此多的移动和破坏
- 从包含 IP 标头片段的二进制文件中读取结构的最佳方法是什么
- 无法理解代码的特定片段:这是一个函数,只是一行还是什么
- 在版本 440 核心中绘制具有纹理的立方体的顶点和片段着色器应该是什么
- 视觉 这两个 c++ 片段有什么区别
- 下面显示的代码片段在 Coliru 和 Ideone 中编译,但根据 iso § 8.5 p6,它不应该,还是我错过了什么?
- 此模板元编程片段中究竟发生了什么
- 添加和删除文件片段以不完全重写它的最有效方法是什么
- 试图使C++(MFC)代码片段易于重用.有什么选择
- C++此代码片段中"<"和">"的含义是什么?
- 下面的代码片段在发布版本中发生了什么?
- 这段c++代码片段在c#中的等价语法是什么?
- 这些代码片段之间的区别是什么?
- 在下面的代码片段中没有省略move构造函数有什么特殊的原因吗?
- 这些代码片段的区别是什么?
- 以下代码片段中 push(po[i]-'0') 对评估后缀表达式的重要性是什么
- 图形互补的这些代码片段有什么区别?