diff --git a/OnlineJudges/lydsy/1224.cpp b/OnlineJudges/lydsy/1224.cpp new file mode 100644 index 0000000..5db5468 --- /dev/null +++ b/OnlineJudges/lydsy/1224.cpp @@ -0,0 +1,24 @@ +#include +const double eps = 1e-10; +int n, m, x, y, ans; +double target, sum[55]; +void dfs(int pos, int cnt, double cur) +{ + double mx = cur + sum[pos - 1 + n - cnt] - sum[pos - 1]; + double mn = cur + sum[m] - sum[m - (n - cnt)]; + if (mn - target > eps || mx - target < -eps) return; + if (cnt == n) ans++; + if (cnt == n || pos == m + 1) return; + dfs(pos + 1, cnt, cur); + dfs(pos + 1, cnt + 1, cur + 1.0 / pos); +} +int main() +{ + scanf("%d%d%d%d", &n, &m, &x, &y); + target = 1.0 * x / y; + for (int i = 1; i <= m; i++) + sum[i] = sum[i - 1] + 1.0 / i; + dfs(1, 0, 0.0); + printf("%d", ans); + return 0; +} \ No newline at end of file diff --git a/OnlineJudges/lydsy/2761.cpp b/OnlineJudges/lydsy/2761.cpp new file mode 100644 index 0000000..b118220 --- /dev/null +++ b/OnlineJudges/lydsy/2761.cpp @@ -0,0 +1,19 @@ +#include +#include +int main() +{ + int t, n; + scanf("%d", &t); + while (t--) + { + scanf("%d", &n); + std::set S; + for (int i = 0, x; i < n; i++) + { + scanf("%d", &x); + if (S.count(x) == 0) + S.insert(x), printf(i == 0 ? "%d" : " %d", x); + } + putchar('\n'); + } +} \ No newline at end of file diff --git a/OnlineJudges/lydsy/3444.cpp b/OnlineJudges/lydsy/3444.cpp new file mode 100644 index 0000000..13e47e7 --- /dev/null +++ b/OnlineJudges/lydsy/3444.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +typedef long long int64; +const int64 mod = 989381; +const int maxn = 500010; +inline void readInt(int &x) +{ + int ch = x = 0; + bool F = false; + for (; !isdigit(ch = getchar()); F = (ch == '-')); + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + F && (x = -x); +} +int fa[maxn], cnt[maxn], deg[maxn], head[maxn], to[maxn << 1], next[maxn << 1], idx, n, m, num; +bool vis[maxn]; +std::map M[maxn]; +int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); } +void link(int x, int y) +{ + int fx = Find(x), fy = Find(y); + if (fx != fy) + { + fa[fx] = fy; + cnt[fy] += cnt[fx]; + cnt[fx] = 0; + } +} +inline void addEdge(int x, int y) +{ + idx++; + to[idx] = y; + next[idx] = head[x]; + head[x] = idx; +} +int fast_pow(int64 base, int pow) +{ + int ans = 1; + for (; pow; base = (base * base) % mod, pow >>= 1) + if (pow & 1) + ans = (ans * base) % mod; + return ans; +} +void dfs(int id, int f) +{ + num++; + vis[id] = true; + if (num > n) return; + for (int cur = head[id]; cur; cur = next[cur]) + if (to[cur] != f) + dfs(to[cur], id); +} +bool check() +{ + for (int i = 1; i <= n; i++) if (deg[i] > 2) return false; + for (int i = 1; i <= n; i++) + if (!vis[i]) + if (deg[i] == 1) dfs(i, 0); + else if (deg[i] == 0) + vis[i] = true, num++; + return num == n; +} +int main() +{ + for (int i = 0; i < maxn; i++) fa[i] = i, cnt[i] = 1; + readInt(n), readInt(m); + for (int i = 0, x, y; i < m; i++) + { + readInt(x), readInt(y); + if (M[x][y] || M[y][x]) continue; + addEdge(x, y), addEdge(y, x); + deg[x]++, deg[y]++; + link(x, y); + M[x][y] = M[y][x] = true; + } + int64 ans = 0; + if (check()) + { + ans = 1; + int l = 0, p = 0; + for (int i = 1; i <= n; i++) + if (fa[i] == i) + (cnt[i] > 1 ? l : p)++; + for (int i = 1; i <= l + p; i++) ans = (ans * i) % mod; + ans = (ans * fast_pow(2, l)) % mod; + } + printf("%lld", ans); + return 0; +} \ No newline at end of file