当前位置:网站首页>2022.7.2 simulation match
2022.7.2 simulation match
2022-07-03 05:33:00 【lAWTYl】
T1 counting
like a breath of fresh air T 1 T1 T1 . A sequence of numbers , No modification , Each inquiry is greater than or equal to x x x The number of . Directly ask each time l o w e r b o u n d ( ) lower_bound() lowerbound() Just like the .
In the examination room 5 5 5 Minutes to finish qwq.
#include<bits/stdc++.h>
using namespace std;
#define in read()
#define MAXN 200200
inline int read(){
int x = 0; char c = getchar();
while(c < '0' or c > '9') c = getchar();
while('0' <= c and c <= '9'){
x = x * 10 + c - '0'; c = getchar();
}
return x;
}
int a[MAXN] = {
0 };
int n = 0; int q = 0;
int main(){
freopen("counting.in", "r", stdin);
freopen("counting.out", "w", stdout);
n = in; q = in;
for(int i = 1; i <= n; i++) a[i] = in;
sort(a + 1, a + n + 1);
while(q--){
int x = in;
cout << n - (lower_bound(a + 1, a + n + 1, x) - a) + 1 << '\n';
}
return 0;
}
T2 graph
Also send sub questions . Just simulate directly according to the meaning of the topic ( The most violent isomorphism qwq).
#include<bits/stdc++.h>
using namespace std;
#define MAXN 101
int n = 0; int m = 0;
int mmap1[MAXN][MAXN] = {
0 };
int mmap2[MAXN][MAXN] = {
0 };
bool flag = 0;
bool chk(int a[]){
bool temp = true;
for(int i = 1; i <= n; i++)
for(int j = 1; j < i; j++){
int x = a[i], y = a[j];
if(mmap1[i][j])
if(!mmap2[x][y]) temp = false;
}
return temp;
}
int a[MAXN] = {
0 };
bool vis[MAXN] = {
0 };
void dfs(int x){
if(x == n + 1){
if(chk(a)) flag = 1;
return;
}
for(int i = 1; i <= n; i++){
if(vis[i]) continue;
vis[i] = 1; a[x] = i;
dfs(x + 1);
vis[i] = 0; a[x] = 0;
}
}
int main(){
freopen("graph.in", "r", stdin);
freopen("graph.out", "w", stdout);
cin >> n >> m;
for(int i = 1; i <= m; i++){
int x = 0, y = 0;
cin >> x >> y;
mmap1[x][y] = mmap1[y][x] = 1;
}
for(int i = 1; i <= m; i++){
int x = 0, y = 0;
cin >> x >> y;
mmap2[x][y] = mmap2[y][x] = 1;
}
dfs(1);
flag ? cout << "Yes" << '\n' : cout << "No" << '\n';
return 0;
}
T3 dishes
At first, I misunderstood the meaning of the topic , Want to become the topological order with the smallest dictionary order . After typing, I found that the sample was wrong , Then I read the topic for a long time to understand .
What you want is to satisfy the topological order and successively Make the number as small as possible in front . Then you will find that the smallest dictionary order is obviously wrong . Then let's consider doing it backwards .
Specifically, we need to make the number smaller successively Try to be at the top , It can be understood that we should make the ones with large numbers rank behind the topological order as much as possible . So we can think of reverse mapping , Then run the topological order with the largest dictionary order on the inverse graph , Finally, reversing the topological order is the required answer ( The essence is greed , But I can't prove the correctness , Just pass the question qwq).
u p d upd upd: The correctness of this method is proved :
First of all, we find the topological order with the largest dictionary order in reverse , therefore 1 1 1 It must be in the back , Because if you move forward a little, the dictionary order will become smaller . Then after the reverse 1 1 1 Right at the front , therefore 1 1 1 The position of must be correct .
Then we use mathematical induction , Before hypothesis k k k The position of the number is correct , Then we need to prove that k + 1 k + 1 k+1 The number is also correct . The method of proof is the same as that just proved 1 1 1 The position of is correct, and the method is exactly the same .
So this practice must be correct .
#include<bits/stdc++.h>
using namespace std;
#define in read()
#define MAXN 100100
#define MAXM MAXN << 2
inline int read(){
int x = 0; char c = getchar();
while(c < '0' or c > '9') c = getchar();
while('0' <= c and c <= '9'){
x = x * 10 + c - '0'; c = getchar();
}
return x;
}
int t = 0;
int n = 0; int m = 0;
int a[MAXN] = {
0 };
int tot = 0; int cnt = 0;
int first[MAXN] = {
0 };
int nxt[MAXM] = {
0 };
int to[MAXM] = {
0 };
int deg[MAXN] = {
0 };
inline void add(int x, int y){
nxt[++tot] = first[x];
first[x] = tot; to[tot] = y; deg[y]++;
}
void init(){
tot = cnt = 0;
memset(a, 0, sizeof(a));
memset(to, 0, sizeof(to));
memset(nxt, 0, sizeof(nxt));
memset(deg, 0, sizeof(deg));
memset(first, 0, sizeof(first));
}
priority_queue<int> q;
void topsort(){
for(int i = 1; i <= n; i++) if(!deg[i]) q.push(i);
while(!q.empty()){
int x = q.top(); q.pop();
a[++cnt] = x;
for(int e = first[x]; e; e = nxt[e]){
int y = to[e];
if(!(--deg[y])) q.push(y);
}
}
}
int main(){
freopen("dishes.in", "r", stdin);
freopen("dishes.out", "w", stdout);
t = in;
while(t--){
init();
n = in; m = in;
for(int i = 1; i <= m; i++){
int x = in, y = in;
add(y, x);
} topsort();
if(cnt < n) cout << "Impossible!\n";
else {
for(int i = n; i >= 1; i--) cout << a[i] << ' '; puts(""); }
}
return 0;
}
T4 network
Portal :HNOI2016 The Internet
front 30 p t s 30pts 30pts You can use a O ( m 2 log n ) O(m^2\log n) O(m2logn) Of violence , Specifically, it's like this .
Obviously we can O ( n log n ) O(n\log n) O(nlogn) After pretreatment O ( log n ) O(\log n) O(logn) seek l c a ( x , y ) lca(x, y) lca(x,y), So we can be in O ( log n ) O(\log n) O(logn) Find out in time d i s ( x , y ) dis(x, y) dis(x,y). So now we only need to know one point m m m Whether in p a t h ( x , y ) path(x, y) path(x,y) On the path of .
If m m m In path p a t h ( x , y ) path(x, y) path(x,y) On , So obviously there is d i s ( x , m ) + d i s ( m , y ) = d i s ( x , y ) dis(x, m) + dis(m, y) = dis(x, y) dis(x,m)+dis(m,y)=dis(x,y). So we can judge from this m m m Whether in p a t h ( x , y ) path(x, y) path(x,y) Yes .
#include<bits/stdc++.h>
using namespace std;
#define in read()
#define MAXN 200200
#define MAXM MAXN << 2
inline int read(){
int x = 0; char c = getchar();
while(c < '0' or c > '9') c = getchar();
while('0' <= c and c <= '9'){
x = x * 10 + c - '0'; c = getchar();
}
return x;
}
int n = 0; int m = 0;
int tot = 0;
int first[MAXN] = {
0 };
int nxt[MAXM] = {
0 };
int to[MAXM] = {
0 };
void add(int x, int y){
nxt[++tot] = first[x];
first[x] = tot; to[tot] = y;
}
int dep[MAXN] = {
0 };
int f[MAXN][35] = {
0 };
void prework(int x, int fa){
dep[x] = dep[fa] + 1;
for(int i = 0; i <= 30; i++)
f[x][i + 1] = f[f[x][i]][i];
for(int e = first[x]; e; e = nxt[e]){
int y = to[e];
if(y == fa) continue;
f[y][0] = x; prework(y, x);
}
}
int query(int x, int y){
if(dep[x] < dep[y]) swap(x, y);
for(int i = 30; i >= 0; i--){
if(dep[f[x][i]] >= dep[y]) x = f[x][i];
if(x == y) return x;
}
for(int i = 30; i >= 0; i--)
if(f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
return f[x][0];
}
int cnt = 0;
struct Tpath{
int t;
int x, y, v;
bool isd;
}path[MAXN];
int main(){
n = in; m = in;
for(int i = 1; i < n; i++){
int x = in, y = in;
add(x, y), add(y, x);
} prework(1, 0);
for(int i = 1; i <= m; i++){
int op = in;
if(op == 0){
int a = in, b = in, v = in;
path[++cnt].x = a, path[cnt].y = b, path[cnt].t = i, path[cnt].v = v;
}
else if(op == 1){
int t = in;
for(int j = 1; j <= cnt; j++) if(path[j].t == t) path[j].isd = 1;
}
else if (op == 2){
int k = in; int ans = -1;
for(int j = 1; j <= cnt; j++){
if(path[j].isd) continue;
int x = path[j].x, y = path[j].y;
int lcaxy = query(x, y), lcaxk = query(x, k), lcaky = query(k, y);
int disxy = dep[x] + dep[y] - 2 * dep[lcaxy];
int disxk = dep[x] + dep[k] - 2 * dep[lcaxk];
int disky = dep[k] + dep[y] - 2 * dep[lcaky];
if(disxy != disxk + disky) ans = max(ans, path[j].v);
}
cout << ans << '\n';
}
}
return 0;
}
Then we found that there are 20 p t s 20pts 20pts It is the case that the whole tree becomes a chain . In this case, the problem becomes a relatively simple operation problem on the sequence . Now it is obvious that this problem has been transformed into a board of tree covering tree ( During the exam, I played the board and didn't adjust it for more than an hour, so I didn't post the code qwq).
边栏推荐
- Ueditor, FCKeditor, kindeditor editor vulnerability
- 聊聊如何利用p6spy进行sql监控
- 6.23 warehouse operation on Thursday
- Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
- Go practice -- generate and read QR codes in golang (skip2 / go QRcode and boombuilder / barcode)
- Introduction to redis and explanation of data types
- 求质数的方法
- SimpleITK学习笔记
- 期末复习(Day5)
- Altaro virtual machine replication failed: "unsupported file type vmgs"
猜你喜欢

About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
![[basic grammar] C language uses for loop to print Pentagram](/img/9e/021c6c0e748e0981d4233f74c83e76.jpg)
[basic grammar] C language uses for loop to print Pentagram

How to use source insight

XML Configuration File

JS scope

Brief introduction of realsense d435i imaging principle

Pessimistic lock and optimistic lock of multithreading

Latest version of source insight

"C and pointer" - Chapter 13 function pointer 1: callback function 2 (combined with template to simplify code)

Gan network thought
随机推荐
今天很多 CTO 都是被幹掉的,因為他沒有成就業務
Go practice -- closures in golang (anonymous functions, closures)
Xaml gradient issue in uwp for some devices
獲取並監控遠程服務器日志
Win10 install pytullet and test
【实战项目】自主web服务器
Can altaro back up Microsoft teams?
Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn
Source insight License Activation
Redis 过期淘汰机制
Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
Audio Focus Series: write a demo to understand audio focus and audiomananger
Common methods of JS array
About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
Technical analysis of qianyuantong multi card aggregation router
请求数据库报错:“could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGram
redis 无法远程连接问题。
获取并监控远程服务器日志
Configure and use Anaconda environment in pycharm
32GB Jetson Orin SOM 不能刷机问题排查