-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jingzhe Tang <t251346744@gmail.com>
- Loading branch information
Showing
395 changed files
with
23,627 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <bitset> | ||
#include <cstdio> | ||
#include <cstring> | ||
#include <algorithm> | ||
#include <functional> | ||
const int maxn = 256; | ||
int t, n, m, kk, tot, cur, pre = 1; | ||
char str[maxn + 1][maxn + 1]; | ||
std::pair<int, int> a[maxn]; | ||
std::bitset<maxn + 1> f[maxn << 1], g[2][maxn]; | ||
int main() | ||
{ | ||
scanf("%d", &t); | ||
for(int Case = 1; Case <= t; ++Case) | ||
{ | ||
scanf("%d%d%d", &n, &m, &kk); | ||
for(int i = 0; i < n; ++i) | ||
scanf("%s", str[i]); | ||
for(int i = 0; i < kk; ++i) | ||
{ | ||
int x, y; | ||
scanf("%d%d", &x, &y); | ||
a[i] = std::make_pair(--x, --y); | ||
} | ||
std::sort(a, a + kk); | ||
for(int i = 0; i < m; ++i) | ||
{ | ||
a[kk++] = std::make_pair(n, i); | ||
str[n][i] = 'W'; | ||
} | ||
tot = 0; | ||
for(int i = 0; i < m; ++i) | ||
{ | ||
g[pre][i].reset(); | ||
g[cur][i].reset(); | ||
g[cur][i].set(i); | ||
} | ||
for(int i = 0, j = 0; i <= n; ++i) | ||
{ | ||
for( ; j < kk && a[j].first == i; ++j) | ||
f[tot++] = g[cur][a[j].second]; | ||
if(i == n) | ||
break; | ||
pre ^= 1; | ||
cur ^= 1; | ||
for(int j = 0; j < m; ++j) | ||
{ | ||
g[cur][j] ^= g[pre][j]; | ||
if(j) | ||
g[cur][j] ^= g[pre][j - 1]; | ||
if(j + 1 < m) | ||
g[cur][j] ^= g[pre][j + 1]; | ||
if(str[i][j] == 'B') | ||
g[cur][j].flip(m); | ||
} | ||
} | ||
bool flag = 1; | ||
int r = 0; | ||
for(int i = 0; i < m; ++i) | ||
{ | ||
int k = -1; | ||
for(int j = r; j < tot; ++j) | ||
if(f[j].test(i)) | ||
{ | ||
k = j; | ||
break; | ||
} | ||
if(k == -1) | ||
continue; | ||
std::swap(f[r], f[k]); | ||
for(int j = i + 1; j < tot; ++j) | ||
if(f[j].test(i)) | ||
f[j] ^= f[i]; | ||
++r; | ||
} | ||
for(int i = r; i < tot; ++i) | ||
if(f[i].test(m)) | ||
{ | ||
flag = 0; | ||
break; | ||
} | ||
printf("Case #%d:\n%s\n", Case, flag ? "YES" : "NO"); | ||
} | ||
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,122 @@ | ||
#include <bitset> | ||
#include <cstdio> | ||
#include <cstring> | ||
#include <algorithm> | ||
const int maxn = 20010, maxs = ((maxn - 1) >> 6) + 1, maxd = 1 << 4; | ||
int t, n, h[maxn << 1], lbt[1 << maxd]; | ||
char str[maxn], buf[maxn << 1 | 1]; | ||
struct Bitset | ||
{ | ||
int n; | ||
size_t len; | ||
unsigned long long data[maxs]; | ||
void init(int n) | ||
{ | ||
this -> n = n; | ||
len = ((n - 1) >> 6) + 1; | ||
memset(data, 0, len * sizeof data[0]); | ||
} | ||
void set(size_t pos) | ||
{ | ||
data[pos >> 6] |= 1ULL << (pos & 63); | ||
} | ||
Bitset operator & (const Bitset &t) const | ||
{ | ||
Bitset ret = {std::min(n, t.n), std::min(len, t.len)}; | ||
for(size_t i = 0; i < ret.len; ++i) | ||
ret.data[i] = data[i] & t.data[i]; | ||
return ret; | ||
} | ||
void shift_left_one() | ||
{ | ||
int last = 0, cur; | ||
for(int i = 0; i < (int)len; ++i) | ||
{ | ||
cur = (data[i] >> 63) & 1; | ||
data[i] <<= 1; | ||
data[i] |= last; | ||
last = cur; | ||
} | ||
++n; | ||
if(n > (int)(len << 6)) | ||
data[len++] = last; | ||
} | ||
void shift_right_one() | ||
{ | ||
int last = 0, cur; | ||
for(int i = len - 1; i >= 0; --i) | ||
{ | ||
cur = data[i] & 1; | ||
data[i] >>= 1; | ||
if(last) | ||
data[i] |= 1ULL << 63; | ||
last = cur; | ||
} | ||
--n; | ||
if(n <= (int)((len - 1) << 6)) | ||
--len; | ||
} | ||
int lowbit() const | ||
{ | ||
for(int i = 0; i < (int)len; ++i) | ||
if(data[i]) | ||
{ | ||
unsigned long long tmp = data[i]; | ||
for(int j = 0; j < 4; ++j, tmp >>= maxd) | ||
if(tmp & ((1 << maxd) - 1)) | ||
return (i << 6) + (j << 4) + lbt[(int)(tmp & ((1 << maxd) - 1))]; | ||
} | ||
return (int)(~0u >> 1); | ||
} | ||
} f, g, w; | ||
int main() | ||
{ | ||
for(int i = 1; i < 1 << maxd; ++i) | ||
lbt[i] = i & 1 ? 0 : lbt[i >> 1] + 1; | ||
scanf("%d", &t); | ||
while(t--) | ||
{ | ||
scanf("%s", str); | ||
n = strlen(str); | ||
for(int i = 0; i < n; ++i) | ||
{ | ||
buf[i << 1] = str[i]; | ||
buf[i << 1 | 1] = '#'; | ||
} | ||
buf[n << 1] = '\0'; | ||
for(int i = 0, mx = 0, id = 0; i <= (n - 1) << 1; ++i) | ||
{ | ||
h[i] = i < mx ? std::min(mx - i, h[(id << 1) - i]) : 0; | ||
for( ; h[i] <= i && buf[i - h[i]] == buf[i + h[i]]; ++h[i]); | ||
if(mx < i + h[i]) | ||
{ | ||
mx = i + h[i]; | ||
id = i; | ||
} | ||
} | ||
f.init(1); | ||
f.set(0); | ||
g.init(n); | ||
for(int i = 0; i < n; ++i) | ||
if(h[i + n - 1] > n - i - 1) | ||
g.set(i); | ||
bool flag = 0; | ||
for(int i = 0; i <= (n - 1) << 1 && !flag; ++i) | ||
{ | ||
int k = (h[i] - (i & 1) - (~(i - h[i]) & 1)) >> 1; | ||
w = f & g; | ||
w.shift_right_one(); | ||
flag |= w.lowbit() <= k; | ||
if(i & 1) | ||
{ | ||
f.shift_left_one(); | ||
if(h[(i + 1) >> 1] > ((i + 1) >> 1)) | ||
f.set(0); | ||
} | ||
else | ||
g.shift_right_one(); | ||
} | ||
puts(flag ? "Yes" : "No"); | ||
} | ||
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,99 @@ | ||
#include <vector> | ||
#include <cstdio> | ||
#include <algorithm> | ||
const int maxn = 100010, maxd = 18, maxs = 11; | ||
struct List | ||
{ | ||
int len, val[maxs]; | ||
void insert(int x) | ||
{ | ||
if(len < maxs) | ||
val[len++] = x; | ||
} | ||
List merge(const List &t) const | ||
{ | ||
List ret = {std::min(len + t.len, maxs)}; | ||
for(int i = 0, j = 0, k = 0; (i < len || j < t.len) && k < ret.len; ++k) | ||
if(j >= t.len || i < len && val[i] <= t.val[j]) | ||
ret.val[k] = val[i++]; | ||
else | ||
ret.val[k] = t.val[j++]; | ||
return ret; | ||
} | ||
} st[maxd][maxn], ans; | ||
int n, m, q, dep[maxn], fa[maxd][maxn]; | ||
std::vector<int> e[maxn]; | ||
void dfs(int u) | ||
{ | ||
for(std::vector<int>::iterator it = e[u].begin(); it != e[u].end(); ++it) | ||
{ | ||
int v = *it; | ||
if(v == fa[0][u]) | ||
continue; | ||
dep[v] = dep[u] + 1; | ||
fa[0][v] = u; | ||
for(int d = 1; fa[d - 1][v]; ++d) | ||
{ | ||
fa[d][v] = fa[d - 1][fa[d - 1][v]]; | ||
st[d][v] = st[d - 1][v].merge(st[d - 1][fa[d - 1][v]]); | ||
} | ||
dfs(v); | ||
} | ||
} | ||
void query(int u, int v, List &ans) | ||
{ | ||
ans = (List){0}; | ||
if(dep[u] > dep[v]) | ||
std::swap(u, v); | ||
for(int d = 0, i = dep[v] - dep[u]; i > 0; ++d, i >>= 1) | ||
if(i & 1) | ||
{ | ||
ans = ans.merge(st[d][v]); | ||
v = fa[d][v]; | ||
} | ||
if(u == v) | ||
{ | ||
ans = ans.merge(st[0][u]); | ||
return; | ||
} | ||
for(int d = maxd - 1; d >= 0; --d) | ||
if(fa[d][u] != fa[d][v]) | ||
{ | ||
ans = ans.merge(st[d][u]); | ||
u = fa[d][u]; | ||
ans = ans.merge(st[d][v]); | ||
v = fa[d][v]; | ||
} | ||
ans = ans.merge(st[0][u]).merge(st[0][v]).merge(st[0][fa[0][u]]); | ||
} | ||
int main() | ||
{ | ||
scanf("%d%d%d", &n, &m, &q); | ||
for(int i = 1; i < n; ++i) | ||
{ | ||
int u, v; | ||
scanf("%d%d", &u, &v); | ||
e[u].push_back(v); | ||
e[v].push_back(u); | ||
} | ||
for(int i = 1; i <= m; ++i) | ||
{ | ||
int x; | ||
scanf("%d", &x); | ||
st[0][x].insert(i); | ||
} | ||
dfs(1); | ||
while(q--) | ||
{ | ||
int u, v, w; | ||
scanf("%d%d%d", &u, &v, &w); | ||
query(u, v, ans); | ||
if(w > ans.len) | ||
w = ans.len; | ||
printf("%d", w); | ||
for(int i = 0; i < w; ++i) | ||
printf(" %d", ans.val[i]); | ||
putchar('\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,47 @@ | ||
#include <map> | ||
#include <cstdio> | ||
#include <algorithm> | ||
typedef long long LL; | ||
const int maxn = 2001; | ||
int n, x[maxn], y[maxn], fm[maxn]; | ||
LL ans; | ||
std::map<std::pair<LL, LL>, int> Hash; | ||
int main() | ||
{ | ||
scanf("%d", &n); | ||
for(int i = 0; i < n; ++i) | ||
{ | ||
int a, b, c; | ||
scanf("%d%d%d", &a, &b, &c); | ||
x[i] = a * c; | ||
y[i] = b * c; | ||
fm[i] = a * a + b * b; | ||
} | ||
for(int i = 0; i < n; ++i) | ||
{ | ||
std::map<std::pair<LL, LL>, int>().swap(Hash); | ||
for(int j = i + 1; j < n; ++j) | ||
{ | ||
LL p = (LL)x[i] * fm[j] - (LL)x[j] * fm[i]; | ||
LL q = (LL)y[i] * fm[j] - (LL)y[j] * fm[i]; | ||
if(p < 0) | ||
{ | ||
p = -p; | ||
q = -q; | ||
} | ||
else if(!p && q < 0) | ||
q = -q; | ||
else if(!p && !q) | ||
{ | ||
ans += n - i - 2; | ||
continue; | ||
} | ||
LL r = std::__gcd(p, q); | ||
p /= r; | ||
q /= r; | ||
ans += Hash[std::make_pair(p, q)]++; | ||
} | ||
} | ||
printf("%I64d\n", ans); | ||
return 0; | ||
} |
Oops, something went wrong.