-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43f67a0
commit f35f0c6
Showing
9 changed files
with
395 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("identifyingConcurrentEvents_UVA334.in"); | ||
ofstream fout("identifyingConcurrentEvents_UVA334.out"); | ||
|
||
const int N = 300, MAX = INT_MAX / 2; | ||
|
||
string join(string a, string b) | ||
{ | ||
int sizeA = a.size(), sizeB = b.size(); | ||
string ans = ""; | ||
|
||
for (int i = 0; i <= sizeA - 1; ++i) | ||
{ | ||
ans += a[i]; | ||
} | ||
|
||
for (int i = 0; i <= sizeB - 1; ++i) | ||
{ | ||
ans += b[i]; | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
int main() | ||
{ | ||
int _case = 0; | ||
while (true) | ||
{ | ||
int n = 0; fin >> n; | ||
if (n == 0) break; | ||
|
||
++_case; | ||
|
||
int t = 0; | ||
vector<string> i_s(N, ""); | ||
map<string, int> s_i; | ||
vector<vector<int>> d(N, vector<int>(N, MAX)); | ||
|
||
for (int c = 1; c <= n; ++c) | ||
{ | ||
int e; fin >> e; | ||
|
||
int last = -1; | ||
for (int k = 1; k <= e; ++k) | ||
{ | ||
string temp; fin >> temp; | ||
|
||
if (s_i.count(temp) == 0) | ||
{ | ||
i_s[t] = temp; | ||
s_i[temp] = t; | ||
++t; | ||
} | ||
|
||
if (k > 1) | ||
{ | ||
d[last][s_i[temp]] = 1; | ||
} | ||
|
||
last = s_i[temp]; | ||
} | ||
} | ||
|
||
for (int u = 0; u <= t - 1; ++u) | ||
{ | ||
d[u][u] = 0; | ||
} | ||
|
||
int m; fin >> m; | ||
for (int c = 1; c <= m; ++c) | ||
{ | ||
string u, v; fin >> u >> v; | ||
|
||
d[s_i[u]][s_i[v]] = 1; | ||
//d[s_i[v]][s_i[u]] = 1; | ||
} | ||
|
||
for (int k = 0; k <= t - 1; ++k) | ||
{ | ||
for (int u = 0; u <= t - 1; ++u) | ||
{ | ||
for (int v = 0; v <= t - 1; ++v) | ||
{ | ||
d[u][v] = min(d[u][v], d[u][k] + d[k][v]); | ||
} | ||
} | ||
} | ||
|
||
|
||
int ans = 0; | ||
vector<string> out; | ||
|
||
for (int u = 0; u <= t - 1; ++u) | ||
{ | ||
for (int v = u + 1; v <= t - 1; ++v) | ||
{ | ||
if (d[u][v] == MAX && d[v][u] == MAX) | ||
{ | ||
++ans; | ||
|
||
//fout << i_s[u] << "->" << i_s[v] << ": " << d[u][v] << '\n'; | ||
//fout << i_s[v] << ' ' << i_s[u] << ": " << d[v][u] << '\n'; | ||
|
||
if (ans <= 2) | ||
{ | ||
out.push_back(join(i_s[u], join("," ,i_s[v]))); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (ans > 0) | ||
{ | ||
fout << "Case " << _case << ", " << ans << " concurrent events:\n"; | ||
int size = out.size(); | ||
for (int i = 0; i <= size - 1; ++i) | ||
{ | ||
fout << '(' << out[i] << ") "; | ||
} | ||
fout << '\n'; | ||
} | ||
else | ||
{ | ||
fout << "Case " << _case << ", no concurrent events.\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,31 @@ | ||
2 | ||
4 w x y z | ||
4 a b c d | ||
3 | ||
a x | ||
x c | ||
b z | ||
3 | ||
4 a b c d | ||
4 e f g h | ||
4 w x y z | ||
3 | ||
a g | ||
g x | ||
b y | ||
2 | ||
2 a b | ||
2 c d | ||
1 | ||
c b | ||
5 | ||
1 a | ||
1 b | ||
1 c | ||
1 d | ||
2 e f | ||
3 | ||
a b | ||
b c | ||
d f | ||
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,8 @@ | ||
Case 1, 8 concurrent events: | ||
(w,a) (w,b) | ||
Case 2, 32 concurrent events: | ||
(a,e) (a,f) | ||
Case 3, 3 concurrent events: | ||
(a,c) (a,d) | ||
Case 4, 10 concurrent events: | ||
(a,d) (a,e) |
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,132 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
const int N = 300, MAX = INT_MAX / 2; | ||
|
||
string join(string a, string b) | ||
{ | ||
int sizeA = a.size(), sizeB = b.size(); | ||
string ans = ""; | ||
|
||
for (int i = 0; i <= sizeA - 1; ++i) | ||
{ | ||
ans += a[i]; | ||
} | ||
|
||
for (int i = 0; i <= sizeB - 1; ++i) | ||
{ | ||
ans += b[i]; | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
int _case = 0; | ||
while (true) | ||
{ | ||
int n = 0; cin >> n; | ||
if (n == 0) break; | ||
|
||
++_case; | ||
|
||
int t = 0; | ||
vector<string> i_s(N, ""); | ||
map<string, int> s_i; | ||
vector<vector<int>> d(N, vector<int>(N, MAX)); | ||
|
||
for (int c = 1; c <= n; ++c) | ||
{ | ||
int e; cin >> e; | ||
|
||
int last = -1; | ||
for (int k = 1; k <= e; ++k) | ||
{ | ||
string temp; cin >> temp; | ||
|
||
if (s_i.count(temp) == 0) | ||
{ | ||
i_s[t] = temp; | ||
s_i[temp] = t; | ||
++t; | ||
} | ||
|
||
if (k > 1) | ||
{ | ||
d[last][s_i[temp]] = 1; | ||
} | ||
|
||
last = s_i[temp]; | ||
} | ||
} | ||
|
||
for (int u = 0; u <= t - 1; ++u) | ||
{ | ||
d[u][u] = 0; | ||
} | ||
|
||
int m; cin >> m; | ||
for (int c = 1; c <= m; ++c) | ||
{ | ||
string u, v; cin >> u >> v; | ||
|
||
d[s_i[u]][s_i[v]] = 1; | ||
} | ||
|
||
for (int k = 0; k <= t - 1; ++k) | ||
{ | ||
for (int u = 0; u <= t - 1; ++u) | ||
{ | ||
for (int v = 0; v <= t - 1; ++v) | ||
{ | ||
d[u][v] = min(d[u][v], d[u][k] + d[k][v]); | ||
} | ||
} | ||
} | ||
|
||
|
||
int ans = 0; | ||
vector<string> out; | ||
|
||
for (int u = 0; u <= t - 1; ++u) | ||
{ | ||
for (int v = u + 1; v <= t - 1; ++v) | ||
{ | ||
if (d[u][v] == MAX && d[v][u] == MAX) | ||
{ | ||
++ans; | ||
|
||
|
||
if (ans <= 2) | ||
{ | ||
out.push_back(join(i_s[u], join("," ,i_s[v]))); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (ans > 0) | ||
{ | ||
cout << "Case " << _case << ", " << ans << " concurrent events:\n"; | ||
int size = out.size(); | ||
for (int i = 0; i <= size - 1; ++i) | ||
{ | ||
cout << '(' << out[i] << ") "; | ||
} | ||
cout << '\n'; | ||
} | ||
else | ||
{ | ||
cout << "Case " << _case << ", no concurrent events.\n"; | ||
} | ||
} | ||
|
||
cout.flush(); | ||
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,38 @@ | ||
#include <bits/stdc++.h> //includes everything, supported in CF, usaco, not POJ | ||
#include "MyRandom.h" | ||
|
||
using namespace std; | ||
|
||
ofstream fout("identifyingConcurrentEvents_UVA334.in"); | ||
|
||
int main() | ||
{ | ||
random rdNum; //note:随机数 | ||
|
||
|
||
int N = rdNum.GetRand(1, 5); | ||
fout << N << "\n"; | ||
vector<int> temp = rdNum.GetUniqueRand(1,N); | ||
|
||
for (int i = 0; i <= N - 1; ++i) | ||
{ | ||
//vector<int> temp=rdNum.GetUniqueRand(1,N1); | ||
fout << temp[i] << " "; | ||
|
||
for (int j = 0; j <= temp[i] - 1; ++j) | ||
{ | ||
fout << "e" << rdNum.GetRand(1, N*2) << " "; | ||
} | ||
|
||
fout << "\n"; | ||
} | ||
fout << 1 << "\n"; | ||
fout << "e" << rdNum.GetRand(1, N) << " " << "e" << rdNum.GetRand(1, N) << "\n"; | ||
|
||
fout << 0 << "\n"; | ||
|
||
|
||
fout.close(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.