bzoj 1800 2048 2120 2208 4195
parent
410ce1de74
commit
02c932275c
@ -0,0 +1,16 @@
|
||||
#include <cstdio>
|
||||
int len[25], ans;
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++) scanf("%d", &len[i]), len[i] += len[i - 1];
|
||||
for (int i = 0 + 1; i <= n; i++)
|
||||
for (int j = i + 1; j <= n; j++)
|
||||
for (int k = j + 1; k <= n; k++)
|
||||
for (int l = k + 1; l <= n; l++)
|
||||
if (len[j] - len[i] == len[l] - len[k] && len[n] - len[l] + len[i] == len[k] - len[j])
|
||||
ans++;
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
const double eps = 1e-10, r = 0.5772156649;
|
||||
typedef long long ll;
|
||||
int main()
|
||||
{
|
||||
double ans;
|
||||
ll n, m;
|
||||
ans = n = m = 0;
|
||||
scanf("%lld%lld", &n, &m);
|
||||
if (n <= 10000)
|
||||
for (int i = 1; i <= n; i++)
|
||||
ans += 0.5 / i;
|
||||
else
|
||||
ans = log(n + 1.0) + r, ans /= 2.0;
|
||||
ans *= m;
|
||||
printf("%d\n", (int)(ans - eps));
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
#include <cstdio>
|
||||
int a[10010], f[20010], map[1001001], idx;
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 1, x; i <= n; i++)
|
||||
{
|
||||
scanf("%d", &x);
|
||||
if (!map[x])
|
||||
map[x] = ++idx;
|
||||
a[i] = map[x];
|
||||
}
|
||||
for (int i = 1, x, y; i <= m; i++)
|
||||
{
|
||||
char ch;
|
||||
scanf("%s%d%d", &ch, &x, &y);
|
||||
if (ch == 'R')
|
||||
{
|
||||
if (!map[y])
|
||||
map[y] = ++idx;
|
||||
a[x] = map[y];
|
||||
}
|
||||
else
|
||||
{
|
||||
int ans = 0;
|
||||
for (int j = x; j <= y; j++)
|
||||
if (f[a[j]] != i)
|
||||
ans++, f[a[j]] = i;
|
||||
printf("%d\n", ans);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
int n, ans;
|
||||
int next[2010 * 2010], to[2010 * 2010], head[2010], idx;
|
||||
char buf[2010];
|
||||
bool vis[2010];
|
||||
void addEdge(int f, int t)
|
||||
{
|
||||
idx++;
|
||||
next[idx] = head[f];
|
||||
head[f] = idx;
|
||||
to[idx] = t;
|
||||
}
|
||||
void dfs(int x)
|
||||
{
|
||||
ans++;
|
||||
vis[x] = true;
|
||||
for (int cur = head[x]; cur; cur = next[cur])
|
||||
if (!vis[to[cur]])
|
||||
dfs(to[cur]);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d\n", &n);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
fgets(buf, 2010, stdin);
|
||||
for (int j = 0; j < n; j++)
|
||||
if (buf[j] == '1')
|
||||
addEdge(i + 1, j + 1);
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
memset(vis, 0, sizeof(vis));
|
||||
dfs(i);
|
||||
}
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
#include <cstdio>
|
||||
#include <cctype>
|
||||
#include <map>
|
||||
inline void readInt(int &x)
|
||||
{
|
||||
int ch = x = 0;
|
||||
while (!isdigit(ch = getchar()));
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
}
|
||||
int fa[2000010], I[1000010], J[1000010], E[1000010];
|
||||
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
|
||||
int main()
|
||||
{
|
||||
int t, n;
|
||||
readInt(t);
|
||||
while (t--)
|
||||
{
|
||||
readInt(n);
|
||||
for (int i = 0; i < 200005; i++) fa[i] = i;
|
||||
std::map<int, int> H;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
readInt(I[i]), readInt(J[i]), readInt(E[i]);
|
||||
if (H.find(I[i]) == H.end()) H[I[i]] = H.size() + 1;
|
||||
if (H.find(J[i]) == H.end()) H[J[i]] = H.size() + 1;
|
||||
if (H.find(E[i]) == H.end()) H[E[i]] = H.size() + 1;
|
||||
}
|
||||
for (int i = 0, x, y; i < n; i++)
|
||||
if (E[i]) if ((x = Find(H[I[i]])) != (y = Find(H[J[i]]))) fa[x] = y;
|
||||
bool flag = true;
|
||||
for (int i = 0, x, y; i < n && flag; i++)
|
||||
if (E[i] ^ 1) if ((x = Find(H[I[i]])) == (y = Find(H[J[i]]))) flag = false;
|
||||
puts(flag ? "YES" : "NO");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in new issue