当前位置:网站首页>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).
边栏推荐
- Pan details of deep learning
- 求质数的方法
- Shanghai daoning, together with American /n software, will provide you with more powerful Internet enterprise communication and security component services
- 3dslam with 16 line lidar and octomap
- Classification and discussion of plane grab detection methods based on learning
- 期末复习DAY8
- Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)
- Altaro o365 total backup subscription plan
- C language program ideas and several commonly used filters
- Pessimistic lock and optimistic lock of multithreading
猜你喜欢

音频焦点系列:手写一个demo理解音频焦点与AudioMananger

Altaro virtual machine replication failed: "unsupported file type vmgs"

@Autowired 导致空指针报错 解决方式
![[practical project] autonomous web server](/img/99/892e600b7203c63bad02adb683c8f2.png)
[practical project] autonomous web server

DEX net 2.0 for crawl detection

Win10 install pytullet and test

Progressive multi grasp detection using grasp path for rgbd images

Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN
![[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)](/img/8b/c10423ee95200a0d94f9fb9dde76eb.jpg)
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)

(subplots usage) Matplotlib how to draw multiple subgraphs (axis field)
随机推荐
[basic grammar] C language uses for loop to print Pentagram
Redis 击穿穿透雪崩
Principles of BTC cryptography
How do I migrate my altaro VM backup configuration to another machine?
Go practice -- design patterns in golang's singleton
Basic introduction of redis and explanation of eight types and transactions
求质数的方法
Installing altaro VM backup
Disassembly and installation of Lenovo r7000 graphics card
Pytorch through load_ state_ Dict load weight
Altaro requirements for starting from backup on Hyper-V
Go practice -- use JWT (JSON web token) in golang
"250000 a year is just the price of cabbage" has become a thing of the past. The annual salary of AI posts has decreased by 8.9%, and the latest salary report has been released
Web APIs exclusivity
期末复习(DAY6)
Get and monitor remote server logs
Xaml gradient issue in uwp for some devices
大二困局(复盘)
Go practice -- closures in golang (anonymous functions, closures)
Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in