Interview record 1

written examination:

1. MySQL index, ordinary index to speed up the query speed, unique index to ensure the uniqueness of the field

2. Private address: the address used in the local area network, NAT-Network Address Translation network address translation, converted to a public network address

Three IP addresses are reserved as private IP addresses:

Class A: 10.0.0.0 ——— 10.255.255.255

Class B: 172.16.0.0-172.31.255.255

Class C: 192.168.0.0-192.168.255.255

3. Although the message arrival time is different, TCP messages will be sorted, UDP will not be sorted

4. High symmetric encryption performance, SSL encryption includes symmetric and asymmetric encryption

5. Doubly linked list inserts node s

6. The probability of a car passing by within 20 minutes is 84%. What is the probability of a car passing by within 10 minutes?

P (20min without car passing) = 1-84% = 0.16; 0.16 = P (first 10min without car passing) * P (last 10min without car passing); P (10min without car passing) = 0.4; P (10min with car passing After) = 0.6

7.38, 25, 74, 63, 52, 48 use H (Key) = Key% 7 The average search times of linear detection method is (1 + 1 + 2 + 1 + 4 + 3) / 6 = 2, average search using zipper method The number of times is (1 + 1 + 2 + 1 + 2 + 1) /6=1.333

8. Process, thread

9. The best time complexity of bubble sorting is O (n), the recording is convenient once, if there is no swap, it can be scanned once. The average complexity is O (n²)

10. The depth of a full binary tree of 32 nodes is 6

11 After the time slice is used up, it will enter the ready state, not enter the blocking state

12. Factory Mode

1. The longest substring

#include<bits\stdc++.h>
using namespace std;
int fun(string s){
	int hash[256];
	fill(hash, hash+256, -1);
	int f=0,res=0;
	for(int i=0;i<s.length();i++){
		if(hash[s[i]]!=-1){
			f = i-hash[s[i]];//找到相同的就更新f 
		}
		else f = f+1;//没有相同的就直接+1 
		hash[s[i]] = i;
		res = max(res, f);
	}
	return res;
}
int main(){
	string s;
	cin>>s;
	cout<<fun(s); 
	return 0;
} 

2. The full array of character arrays (Alas, the full array cannot be written, dishes)

3. The largest sum divisible by three

Idea: O (n), all results are added after traversing once. Case ①res% 3 == 0 ②res% 3 == 1 (caused by one 3 surplus 1 or two 3 surplus 2) ③res% 3 == 2 (resulted by two 3 surplus 1 or one 3 surplus 2). The code is a bit ugly

#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int fun(vector<int> &v){
	priority_queue<int, vector<int>, less<int> > tmp1, tmp2;
	int res=0;
	for(int i=0;i<v.size();i++){
		res = res+v[i];
		if(v[i]%3==1){
			if(tmp1.size()<2) tmp1.push(v[i]);
			else{
				if(v[i]<tmp1.top()){
					tmp1.pop();
					tmp1.push(v[i]);
				}
			}
		}
		else if(v[i]%3==2){
			if(tmp2.size()<2) tmp2.push(v[i]);
			else{
				if(v[i]<tmp2.top()){
					tmp2.pop();
					tmp2.push(v[i]);
				}
			}
		}
	}
	if(res%3==1){
		int min_yu1=999999, add_yu2=999999;
		if(tmp1.size()>=1){
			while(tmp1.size()!=0){
				min_yu1 = min(min_yu1, tmp1.top());
				tmp1.pop();
			}
		}
		if(tmp2.size()==2){
			add_yu2=0;
			while(tmp2.size()!=0){
				add_yu2 +=  tmp2.top();
				tmp2.pop();
			}
		}
		if(min_yu1!=999999 && add_yu2!=999999)
			res = res - min(min_yu1, add_yu2);
		else if(min_yu1==999999) res = res - add_yu2;
		else if(add_yu2==999999) res = res - min_yu1;
	}
	else if(res%3==2){
		int min_yu2=999999, add_yu1=999999;
		if(tmp2.size()>=1){
			while(tmp2.size()!=0){
				min_yu2 = min(min_yu2, tmp2.top());
				tmp2.pop();
			}
		}
		if(tmp1.size()==2){
			add_yu1=0;
			while(tmp1.size()!=0){
				add_yu1 +=  tmp1.top();
				tmp1.pop();
			}
		}
		if(min_yu2!=999999 && add_yu1!=999999)
			res = res - min(min_yu2, add_yu1);
		else if(min_yu2==999999) res = res - add_yu1;
		else if(add_yu1==999999) res = res - min_yu2;
	}
	return res;
}
int main(){
	//获取数据
	vector<int> vv;
	int x;
	while(~scanf("%d ", &x)){
		vv.push_back(x);
	}
	cout<<fun(vv);
	return 0;
}

 

Published 248 original articles · Like 29 · Visits 30,000+

Guess you like

Origin blog.csdn.net/weixin_38603360/article/details/105165097