-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from elite-lang/dev
修复BasicBlock的bug
- Loading branch information
Showing
47 changed files
with
2,724 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 八皇后问题 | ||
|
||
int sum = 0; | ||
int upperlim = 1; | ||
|
||
// 试探算法从最右边的列开始。 | ||
void test(int row, int ld, int rd) | ||
{ | ||
if (row != upperlim) | ||
{ | ||
// row,ld,rd进行“或”运算,求得所有可以放置皇后的列,对应位为0, | ||
// 然后再取反后“与”上全1的数,来求得当前所有可以放置皇后的位置,对应列改为1 | ||
// 也就是求取当前哪些列可以放置皇后 | ||
int pos = upperlim & ~(row | ld | rd); | ||
while (pos != 0) // 0 -- 皇后没有地方可放,回溯 | ||
{ | ||
// 拷贝pos最右边为1的bit,其余bit置0 | ||
// 也就是取得可以放皇后的最右边的列 | ||
int p = pos & -pos; | ||
|
||
// 将pos最右边为1的bit清零 | ||
// 也就是为获取下一次的最右可用列使用做准备, | ||
// 程序将来会回溯到这个位置继续试探 | ||
pos -= p; | ||
|
||
// row + p,将当前列置1,表示记录这次皇后放置的列。 | ||
// (ld + p) << 1,标记当前皇后左边相邻的列不允许下一个皇后放置。 | ||
// (ld + p) >> 1,标记当前皇后右边相邻的列不允许下一个皇后放置。 | ||
// 此处的移位操作实际上是记录对角线上的限制,只是因为问题都化归 | ||
// 到一行网格上来解决,所以表示为列的限制就可以了。显然,随着移位 | ||
// 在每次选择列之前进行,原来N×N网格中某个已放置的皇后针对其对角线 | ||
// 上产生的限制都被记录下来了 | ||
test(row + p, (ld + p) << 1, (rd + p) >> 1); | ||
} | ||
} | ||
else | ||
{ | ||
// row的所有位都为1,即找到了一个成功的布局,回溯 | ||
sum++; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int n = 8; | ||
upperlim = (upperlim << n) - 1; | ||
test(0, 0, 0); | ||
printf("共有%ld种排列\\n", sum); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
92 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 质因数分解 | ||
|
||
int main(){ | ||
int n = 90; | ||
printf("%d=", n); | ||
// n>=2才执行下面的循环 | ||
for(int i=2; i<=n; i++){ | ||
while(n!=i){ | ||
if(n%i==0){ | ||
printf("%d*",i); | ||
n=n/i; | ||
}else | ||
break; | ||
} | ||
} | ||
printf("%d\n",n); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
90=2*3*3*5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 测试可能有歧义的符号 | ||
|
||
int main() { | ||
int x = 10; | ||
if (x == 10) { | ||
int x = 20; | ||
if (x == 20) | ||
printf("1"); | ||
else | ||
printf("0"); | ||
} | ||
if (x == 10) | ||
printf("1"); | ||
else | ||
printf("0"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.