当前位置:网站首页>1.19 learning summary
1.19 learning summary
2022-06-26 04:35:00 【After all, I still walk alone】
I have finished all the topics today . Just do the problem solving , When reviewing . I did a question today . I think it's more interesting . The title is as follows .
This question is very interesting . The main requirement is the middle order . The title also tells us . The middle order is not fixed . In fact, if you carefully observe the conditions given by the topic , You will find that this sample actually gives you a hint . The example shows three elements . But we know these three elements . A forest of trees Depth of three . Why? ? You can observe it . According to the requirements of the preceding sequence . Behind the root It's a left-right subtree ,. And in the following sequence , In front of the root are left and right subtrees . Therefore, whether it is pre order or post order The left and right sides of the subtree do not change . But in The example changes . That means they are not left or right Subtree relation . But the root And child nodes . And it has only one child node . This nature It is also the key for me to solve this problem . My method is to traverse Find from . Want to bccb Such . Find one . That means there are two possibilities . That is to the power of two ? This is my idea of doing this problem .
#include<stdio.h>
#include<string.h>
#include<math.h>
int ans;
char str1[500],str2[500];
int main()
{
scanf("%s",str1);
scanf("%s",str2);
int m=strlen(str1);
int m1=strlen(str2);
for(int i=0;i<m;i++){
for(int j=m1-1;j>0;j--){
if(str1[i]==str2[j]&&str1[i+1]==str2[j-1]){
ans++;}}}
int s;
s=pow(2,ans);
printf("%d",s);
return 0;
}
There is also a topic of joint search , I want to say .
The title is as follows .
This topic has two sets of data . So I used two parallel search sets . Merge their relationships separately . Then traverse to find out all that are related to Xiao Ming and Xiao Hong Common ancestor data . So I found . Two companies , Xiao Ming and Xiao Hong's friends .
The only trouble is . The other group is negative . So we have to deal with it in a little way . I am turning him into a positive number . Add one more n.
The specific code is as follows . This question is still relatively simple .
#include<stdio.h>
#include <algorithm>
using namespace std;
int n,m,p,q,ansm=0,ans1=0,f[1000000];
int find(int x)
{
if(f[x]==x){
return x;}
else {
f[x]=find(f[x]);
return f[x];}
}
void s(int x,int y)
{
f[find(x)]=find(y);
}
int main()
{
scanf("%d%d%d%d",&n,&m,&p,&q);
for(int i=1;i<=n+m;++i)
f[i]=i;
for(int i=1;i<=p;++i)
{
int a,b;
scanf("%d%d",&a,&b);
s(a,b);
}
for(int i=1;i<=q;++i)
{
int a,b;
scanf("%d%d",&a,&b);
a*=-1;b*=-1;
s(a+n,b+n);
}
for(int i=1;i<=n;++i){
if(find(i)==find(1)){
ansm++;}}
for(int i=n+1;i<=n+m;++i){
if(find(i)==find(n+1)){
ans1++;}}
printf("%d",min(ans1,ansm));
return 0;
}
边栏推荐
- Physical design of database design (2)
- numpy 索引及切片
- Modify the number of Oracle connections
- PHP design function getmaxstr to find the longest symmetric string in a string - [original]
- Install dbeaver and connect Clickhouse
- pip 批量完全卸载包
- Thinkphp6 implements a simple lottery system
- Microsoft prohibits Russian users from downloading and installing win10/11
- Implementation of seven classes of BlockingQueue interface
- Essential foundation of programming - Summary of written interview examination sites - computer network (1) overview
猜你喜欢
Thinkphp6 using kindeditor
Tp6 controller does not exist: app\index\controller\index
Modify the number of Oracle connections
[Qunhui] this suite requires you to start PgSQL adapter service
CDN with OSS acceleration
Nailing open platform - applet development practice (nailing applet server side)
Gateway can not connect to tcp://127.0.0.1: Connection refused
Alipay failed to verify the signature (sandbox test indicates fishing risk?) [original]
Zhimeng CMS will file a lawsuit against infringing websites
Threejs special sky box materials, five kinds of sky box materials are downloaded for free
随机推荐
Tp6 controller does not exist: app\index\controller\index
PHP inherited in class return does not work
Introduction to markdown grammar
Navicat connects the pit of shardingsphere sub table and sub library plug-ins
MySQL's built-in performance testing tool, mysqlslap, performs stress testing
Zhubo Huangyu: you can try these non-agricultural operation skills
Yapi cross domain request plug-in installation
Understand CGI and fastcgi
OSS CDN alicloud configuration method
Motivational skills for achieving goals
Go SQL parsing time Time type
Thinkphp6 using kindeditor
C generic
Install cenos in the virtual machine
Review of number theory
2020-12-18
ctf [RoarCTF 2019]easy_ calc
Fastadmin always prompts sqlstate[23000]: integrity constraint violation: 1052 column 'ID' in order clause is am
List of provinces, cities and counties in China
Ueeditor automatically appends P tags to rich text.br tags always wrap.br tag solutions