洛谷P4589 [TJOI2018]智力竞赛(二分答案 二分图匹配)

Sol

TJOI怎么净出板子题

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define ull signed long long
#define LL long long
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 1001, mod = 1e9 + 7, INF = 1e9 + 10;
const double eps = 1e-9;
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;}
template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;}
template <typename A> inline void debug(A a){cout << a << '\n';}
template <typename A> inline LL sqr(A x){return 1ll * x * x;}
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, a[MAXN], ans[MAXN], vis[MAXN], tim = 1, link[MAXN], st[MAXN], top;
bitset<MAXN> can[MAXN];
bool dfs(int x) {
for(int i = 1; i <= top; i++) {
if(can[st[x]][st[i]]) {
if(vis[i] == tim) continue;
vis[i] = tim;
}
}
return 0;
}
bool check(int val) {
for(int i = 1; i <= M; i++) if(a[i] < val) st[++top] = i;
int ans = 0;
for(int i = 1; i <= top; i++, tim++) if(dfs(i)) ans++;
}
signed main() {
int mx = 0;
for(int i = 1; i <= M; i++) {
for(int j = 1; j <= k; j++) can[i][read()] = 1;
}
for(int k = 1; k <= M; k++)
for(int i = 1; i <= M; i++)
if(can[i][k])
can[i] |= can[k];
int l = 0, r = mx, ans = 0;
while(l <= r) {
int mid = l + r >> 1;
if(check(mid)) ans = mid, l = mid + 1;
else r = mid - 1;
}
if(ans >= mx) puts("AK");
else cout << ans;
return 0;
}
/*

*/

0 条评论

• cf121C. Lucky Permutation(康托展开)

由于阶乘的数量增长非常迅速，而$$k$$又非常小，那么显然最后的序列只有最后几位会发生改变。

• cf900D. Unusual Sequences(容斥 莫比乌斯反演)

考虑容斥，设$$g[i]$$表示满足和为$$i$$的序列的方案数，显然$$g[i] = 2^{i-1}$$(插板后每空位放不放)

• BZOJ3122: [Sdoi2013]随机数生成器(BSGS)

直接把$$X_{i+1} = (aX_i + b) \pmod P$$展开，推到最后会得到这么个玩意儿