当前位置:网站首页>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;
}

原网站

版权声明
本文为[After all, I still walk alone]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180530061342.html