mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-14 07:18:47 +00:00
Compare commits
3 Commits
ca73bb7c70
...
b3f66bd654
Author | SHA1 | Date | |
---|---|---|---|
b3f66bd654 | |||
1f2d950fb9 | |||
1018034552 |
62
AtCoder/ABC265/C/C.cpp
Normal file
62
AtCoder/ABC265/C/C.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 505;
|
||||
|
||||
int n, m;
|
||||
char g[N][N];
|
||||
bool vis[N][N];
|
||||
|
||||
void dfs(int x, int y, int lx, int ly) {
|
||||
if (x <= 0 || x > n || y <= 0 || y > m) {
|
||||
cout << lx << ' ' << ly << endl;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (vis[x][y]) {
|
||||
cout << -1 << endl;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
vis[x][y] = true;
|
||||
switch (g[x][y]) {
|
||||
case 'U': {
|
||||
dfs(x - 1, y, x, y);
|
||||
break;
|
||||
}
|
||||
case 'D': {
|
||||
dfs(x + 1, y, x, y);
|
||||
break;
|
||||
}
|
||||
case 'L': {
|
||||
dfs(x, y - 1, x, y);
|
||||
break;
|
||||
}
|
||||
case 'R': {
|
||||
dfs(x, y + 1, x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= m; j++) {
|
||||
cin >> g[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
dfs(1, 1, 1, 1);
|
||||
|
||||
return 0;
|
||||
}
|
56
S2OJ/1505/1505.cpp
Normal file
56
S2OJ/1505/1505.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 100005;
|
||||
|
||||
int n, m, q, d_a[N], d_b[N];
|
||||
bool a[N], b[N];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> b[i];
|
||||
}
|
||||
|
||||
if (a[1] != a[n]) d_a[0] = 1;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
d_a[i] = d_a[i - 1] + (a[i] != a[i + 1]);
|
||||
}
|
||||
|
||||
if (b[1] != b[m]) d_b[0] = 1;
|
||||
for (int i = 1; i <= m; i++) {
|
||||
d_b[i] = d_b[i - 1] + (b[i] != b[i + 1]);
|
||||
}
|
||||
|
||||
cin >> q;
|
||||
|
||||
while (q--) {
|
||||
std::pair<int, int> s, e;
|
||||
|
||||
cin >> s.first >> s.second >> e.first >> e.second;
|
||||
|
||||
cout << std::min({
|
||||
std::abs(d_a[s.first - 1] - d_a[e.first - 1]),
|
||||
d_a[n - 1] - d_a[std::max(s.first, e.first) - 1] + d_a[std::min(s.first, e.first) - 1],
|
||||
}) + std::min({
|
||||
std::abs(d_b[s.second - 1] - d_b[e.second - 1]),
|
||||
d_b[m - 1] - d_b[std::max(s.second, e.second) - 1] + d_b[std::min(s.second, e.second) - 1],
|
||||
})
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1505/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
95
S2OJ/1506/1506.cpp
Normal file
95
S2OJ/1506/1506.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 205;
|
||||
|
||||
int n, ans;
|
||||
bool g[N][N], g2[N][N];
|
||||
|
||||
// Tarjan
|
||||
int cnt, dfn[N], low[N];
|
||||
int scc_cnt, id[N], siz[N];
|
||||
int dout[N], din[N];
|
||||
bool vis[N];
|
||||
std::stack<int> st;
|
||||
|
||||
void tarjan(int u) {
|
||||
dfn[u] = low[u] = ++cnt;
|
||||
st.push(u);
|
||||
vis[u] = true;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (!g[u][i]) continue;
|
||||
|
||||
if (!dfn[i]) {
|
||||
tarjan(i);
|
||||
low[u] = std::min(low[u], low[i]);
|
||||
} else if (vis[i]) {
|
||||
low[u] = std::min(low[u], dfn[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (dfn[u] == low[u]) {
|
||||
scc_cnt++;
|
||||
|
||||
int v;
|
||||
do {
|
||||
v = st.top();
|
||||
st.pop();
|
||||
vis[v] = false;
|
||||
id[v] = scc_cnt;
|
||||
siz[scc_cnt]++;
|
||||
} while (v != u);
|
||||
|
||||
if (siz[scc_cnt] > 1) ans += siz[scc_cnt];
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
cin >> g[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (!dfn[i]) tarjan(i);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
if (g[i][j] && id[i] != id[j]) {
|
||||
g2[id[i]][id[j]] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= scc_cnt; i++) {
|
||||
for (int j = 1; j <= scc_cnt; j++) {
|
||||
for (int k = 1; k <= scc_cnt; k++) {
|
||||
if (i != j && j != k && g2[i][k] && g2[k][j]) {
|
||||
g2[i][j] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= scc_cnt; i++) {
|
||||
for (int j = 1; j <= scc_cnt; j++) {
|
||||
if (g2[i][j]) ans++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1506/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user