mit的难题(有误)
This commit is contained in:
parent
7de6349786
commit
3912ab2d30
3
4083_mit/Readme.md
Normal file
3
4083_mit/Readme.md
Normal file
@ -0,0 +1,3 @@
|
||||
# 标题
|
||||
|
||||
* 内容
|
3
4083_mit/doc/Readme.md
Normal file
3
4083_mit/doc/Readme.md
Normal file
@ -0,0 +1,3 @@
|
||||
# 标题
|
||||
|
||||
* 内容
|
BIN
4083_mit/doc/mit的难题.pdf
Normal file
BIN
4083_mit/doc/mit的难题.pdf
Normal file
Binary file not shown.
6
4083_mit/main.cpp
Normal file
6
4083_mit/main.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hello Easy C++ project!" << std::endl;
|
||||
}
|
BIN
4083_mit/main.exe
Normal file
BIN
4083_mit/main.exe
Normal file
Binary file not shown.
41
4083_mit/mit.cpp
Normal file
41
4083_mit/mit.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int n, m, ans = 0;
|
||||
int pa[100001] = { 0 }, zhi[100001] = { 0 };
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= m; i++) {
|
||||
char u;
|
||||
int a, b;
|
||||
cin >> u >> a >> b;
|
||||
//00
|
||||
if (pa[a] == 0 && pa[b] == 0) {
|
||||
ans++;
|
||||
pa[a] = ans;
|
||||
pa[b] = ans;
|
||||
zhi[ans] = ans;
|
||||
} else {
|
||||
//11
|
||||
while(zhi[pa[a]] !=pa[a]){
|
||||
a=zhi[pa[a]]
|
||||
}
|
||||
if (zhi[pa[a]] != zhi[pa[b]] && pa[a] > 0 && pa[b] > 0) {
|
||||
ans--;
|
||||
zhi[pa[a]] = zhi[pa[b]];
|
||||
} else {
|
||||
//10
|
||||
if (zhi[pa[a]] > 0) {
|
||||
pa[b] = pa[a];
|
||||
} else {
|
||||
//01
|
||||
pa[a] = pa[b];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << "1";
|
||||
for (int i = 1; i <= ans; i++) {
|
||||
cout << "0";
|
||||
}
|
||||
}
|
BIN
4083_mit/mit.exe
Normal file
BIN
4083_mit/mit.exe
Normal file
Binary file not shown.
5384
4083_mit/test/In1 (19).txt
Normal file
5384
4083_mit/test/In1 (19).txt
Normal file
File diff suppressed because it is too large
Load Diff
12726
4083_mit/test/In2 (12).txt
Normal file
12726
4083_mit/test/In2 (12).txt
Normal file
File diff suppressed because it is too large
Load Diff
3
4083_mit/test/in.txt
Normal file
3
4083_mit/test/in.txt
Normal file
@ -0,0 +1,3 @@
|
||||
3 2
|
||||
S 1 2
|
||||
D 3 2
|
18
4083_mit/test/out.txt
Normal file
18
4083_mit/test/out.txt
Normal file
@ -0,0 +1,18 @@
|
||||
## z:\Chao\src\4083_mit\test\in.txt
|
||||
2020/04/06 周一 12:33:23.89
|
||||
10
|
||||
-----------------------------------------------
|
||||
Process exited after 260 ms with return value 0
|
||||
|
||||
## z:\Chao\src\4083_mit\test\In1 (19).txt
|
||||
2020/04/06 周一 12:33:23.89
|
||||
1
|
||||
-----------------------------------------------
|
||||
Process exited after 190 ms with return value 0
|
||||
|
||||
## z:\Chao\src\4083_mit\test\In2 (12).txt
|
||||
2020/04/06 周一 12:33:23.89
|
||||
1
|
||||
-----------------------------------------------
|
||||
Process exited after 210 ms with return value 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user