10.31 模拟赛
A LIS
考虑每个数字前从 $ m $ 降序构造到 $ a_i $ 即可。
#include <iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
#define MAXN 300006
int n , m , k;
int A[MAXN];
vector<int> ans;
int main() {
cin >> n >> m >> k;
for( int i = 1 ; i <= k ; ++ i ) scanf("%d",&A[i]);
int lef = n - k;
for( int i = 1 ; i <= k ; ++ i ) {
int cur = m;
while( lef && cur > A[i] ) ans.push_back(cur), -- cur ,-- lef;
ans.push_back( A[i] );
}
if( lef ) return puts("No") , 0;
puts("Yes");
for( auto it : ans ) printf("%d ",it);
}
T2 图论
看到数据范围考虑暴搜,枚举答案(其实也就 $ 2n $)只要倒着枚举以前的边就显然仍然存在。
于是每次加边后进行一下宽搜,每个边只会入队一次,每次扩展是 $ O(n) $ 故总复杂度 $ O(n^3) + O(n^3) $
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
#define MAXN 1006
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
int n , m , cnt;
int deg[MAXN] , G[MAXN][MAXN];
queue<pii> Q;
void bfs( int x ) {
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (!G[i][j] && deg[i] + deg[j] >= x) Q.push(make_pair(i, j)), G[i][j] = G[j][i] = 1;
while (!Q.empty()) {
pii now = Q.front(); Q.pop();
++ deg[now.fi] , ++ deg[now.se];
++ cnt;
int u = now.first, v = now.second;
for (int i = 1; i <= n; i++)
if (i != u && !G[u][i] && deg[u] + deg[i] >= x)
G[u][i] = G[i][u] = 1 , Q.push(mp(u, i));
for (int i = 1; i <= n; i++)
if (i != v && !G[v][i] && deg[v] + deg[i] >= x)
G[v][i] = G[i][v] = 1 , Q.push(mp(v, i));
}
}
int main() {
cin >> n >> m;
for (int i = 1 , u , v; i <= m; ++ i)
scanf("%d%d", &u, &v) , deg[u]++, deg[v]++ , G[u][v] = G[v][u] = 1 , cnt++;
int all = n * ( n - 1 ) / 2;
for (int i = 2 * n; i >= 0; -- i) {
bfs( i );
if (cnt == all)
return printf("%d
", i) , 0;
}
}
T3 防御
考虑每个点通过这堵墙投影到 $ x $ 轴上一段区间,于是就成了一个区间包含问题(二维偏序)
然后就鸽掉了。。精度误差毒瘤。