bzoj 1224 2761 3444
parent
8cffad9d6a
commit
90b7d99f01
@ -0,0 +1,24 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
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;
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <set>
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int t, n;
|
||||||
|
scanf("%d", &t);
|
||||||
|
while (t--)
|
||||||
|
{
|
||||||
|
scanf("%d", &n);
|
||||||
|
std::set<int> 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <cctype>
|
||||||
|
#include <map>
|
||||||
|
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<int, bool> 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;
|
||||||
|
}
|
||||||
Loading…
Reference in new issue