Day1 in Ji Zhong's travel notes

Posted by joopeon on Thu, 20 Jan 2022 07:19:46 +0100

preface

Ji Zhong arrived 1 day ago. The dormitory was very hard. He was confused at noon: wear long sleeves
Afternoon confusing behavior: getting lost in Jizhong
The topic is very good. The children like it very much. They will come again next time

morning

In the morning, I had dinner with stoorz and myd. myd was crying for poverty, which means he was lying to ghosts
I spent the rest of my time in the simulation game. I was Rank9, very delicious, only 115, (wj65, myd lower). Velix giant AC2 was successful, Rank2
So AJ asked us to revise question 2? Velix AK IOI
This side has been booked up in the afternoon
Personally, rp=300

noon

Anonymous comrades are playing chess. I won't report it here, * * *: I've lost both horses
Cong's WJ in Tucao, XJQ said he wanted to make complaints about it, and WJ said he must come.
I was confused and wore long sleeves. I became the only long sleeved school uniform in the afternoon lecture
Personally, I think rp=100

afternoon

In the afternoon, I asked someone to give a lecture. I'm honored to talk about the T4 90 leave algorithm and harvest the ignorant face of a computer room
Students under the stage: I don't understand. Can you speak slowly??
Personally, I'm very GG. Who still remembers the simulation algorithm
After dinner, myd continued to cry. He had only 26 yuan (thanks for myd's correction) and 29 yuan. We said: just divide it
After dinner, wj and I went back to the computer room to change the questions. Now we have finished
After the change, I went downstairs for a walk, and then

Ji Zhong lost his way

Vaguely strolled to the playground, and then the player said: I was late for the last ball, and then Jizhong's bell rang. I was scared to death. I ran around Jizhong for half a week and ran to the swimming pool to find my way

Feeling rp=-100

night

In the evening, I have nothing to do to write travel notes and explanations
Here is a comment:
wj: hurry up and write your travel notes. We're waiting to read funny novels

T1

Description

Small A has always believed that if in A sequence An composed of N integers, there exists A m + A n + A p = A i ( 1 < = m , n , p < i ) A_m + A_n + A_p = A_i(1 <= m, n, p < i) Am + An + Ap = Ai (1 < = m, n, p < I) (m, n, p can be the same), A i A_i Ai is A "good element". Now, little A has A sequence. He wants to know how many "good elements" there are in this sequence. Please help him.

Input

The first line has only one positive integer N, meaning as above.

The second row contains N integers representing the sequence An.

Output

Output an integer representing the number of "good elements" in this sequence.

Sample Input

Input 1:
2
1 3
Input 2:
6
1 2 3 5 7 10
Input 3:
3

-1 2 0

Sample Output

Output 1:
1
Output 2:
4
Output 3:
1

thinking

SBhash, ruin my youth, consume my money and waste my life
This question O(n^4) explodes the zero player to report for duty
Positive solution:
Transfer: A m + A n = A i − A p A_m+A_n=A_i-A_p Am​+An​=Ai​−Ap​
Put left hash and right hash, n can be solved
code:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int hash[30000005],n,a[5001],ans;
void h(int x)
{
	int u=x%30000001+30000001;
	u%=30000001;
	while (hash[u]!=x&&hash[u]!=0) u=(u+1)%30000005;
	hash[u]=x;
	return;
}
bool h2(int x)
{
	int u=x%30000001+30000001;
	u%=30000001;
	while (hash[u]!=x&&hash[u]!=0) u=(u+1)%30000005;
	return hash[u]!=0;
}
int main()
{
	freopen("good.in","r",stdin);
	freopen("good.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	bool o=0;
	for (int i=1;i<=n;i++)
	{
		if (a[i]==0&&o)
		{
			ans++;
			continue;
		}
		if (a[i]==0) o=1;
		for (int j=1;j<i;j++)
		{
			if (h2(a[i]-a[j]))
			{
				ans++;
				break;
			}
		}
		for (int j=1;j<=i;j++)
		{
			h(a[i]+a[j]);
		}
	}
	printf("%d",ans);
	fclose(stdin);
	fclose(stdout);
	return 0;
}

T2

Description

n points are given in the plane. Note that the smallest point of abscissa is A and the largest point is B. now Zxd wants to know the shortest path from A to B and back to A when each point passes through once (twice at point A). But he is A patient with obsessive-compulsive disorder. He has many strange requirements and restrictions:

  1. When walking from A to B, you can only go from the point with small abscissa to the point with large abscissa.

  2. When returning from B to A, you can only go from the point with large abscissa to the point with small abscissa.

  3. There are two special points b1 and b2. b1 is on the road from 0 to n-1 and b2 is on the road from n-1 to 0.

Please help him solve this problem and help him treat it!

Input

The first line contains three integers n, b1, b2, (0 < b1, b2 < n-1 and b1 < > b2). N represents the number of points, numbered from 0 to n-1, and b1 and b2 are the numbers of two special points.

In the following n lines, two integers x and Y in each line represent the coordinates of the point (0 < = x, y < = 2000), in order from point 0

give. In order to facilitate his treatment, Doctor Gao ensures that the abscissa of all points are different, and has arranged the given points in x-increasing order.

Output

Only one line, output the shortest path length (accurate to 2 digits after the decimal point)

Sample Input

5 1 3

1 3

3 4

4 1

7 5

8 3

Sample Output

18.18

thinking

Long live dfs10!!
Comrades myd of Ke AI used dfs successfully for 20 years
wcr: play nm!
Round trip = 2 times, from left to right
dis(x,y) is the straight-line distance of point X and point y
Obviously dp, let f i , j f_{i,j} fi,j , is the optimal solution from left to right for the first time to the i-th, and from left to right for the second time to the j-th
f i , j + d i s ( i , k ) = > f k , j f_{i,j}+dis(i,k)=>f_{k,j} fi,j​+dis(i,k)=>fk,j​
f i , j + d i s ( j , k ) = > f i , k f_{i,j}+dis(j,k)=>f_{i,k} fi,j​+dis(j,k)=>fi,k​
Note that both ends of the first and second pass are 1, N, so we need to calculate n-1 to n one more time
code:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int x[1001],y[1001];
double p(int xx,int yy)
{
	return sqrt((x[xx]-x[yy])*(x[xx]-x[yy])+(y[xx]-y[yy])*(y[xx]-y[yy]));
}
int n,b1,b2;
double ans[1001][1001];
int main()
{
	freopen("path.in","r",stdin);
	freopen("path.out","w",stdout);
	scanf("%d%d%d",&n,&b1,&b2);
	for (int i=0;i<n;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
	}
	x[n]=x[n-1],y[n]=y[n-1];
	memset(ans,0x7f7f7f7f,sizeof(ans));
	ans[0][0]=0;
	for (int i=0;i<=n;i++)
	{
		for (int j=0;j<=n;j++)
		{
			int k=max(i,j)+1;
			if (k==b1) ans[k][j]=min(ans[i][j]+p(i,k),ans[k][j]);
			else if (k==b2) ans[i][k]=min(ans[i][j]+p(j,k),ans[i][k]);
			else
			{
				ans[k][j]=min(ans[i][j]+p(i,k),ans[k][j]);
				ans[i][k]=min(ans[i][j]+p(j,k),ans[i][k]);
			}
		}
	}
	printf("%.2lf",min(ans[n][n-1],ans[n-1][n]));
	fclose(stdin);
	fclose(stdout);
	return 0;
}

T3

thinking

The most difficult problem in the audience, there is a 90 point wrong solution konjac
Mourn the data with fooling
Personal positive solution:
First operate the input:

  1. Parallel block
  2. Write down the left and right of the block where each point is located
  3. The non replaceable point can be set as [i, i]

set up s i , j s_{i,j} si,j , is the maximum number of matches in the block starting from i for S and j for T
Only the leftmost point of each block is considered( l i l_i li) and processed one by one through the pointer s l i , j s_{l_i,j} sli, J, using some order (when we calculate j+1, we can clear the influence of the first j), here is O(n2), code interception:

for (int i=0;i<y.size();i++)
	{
		if (a[i].l==i)//When a point is the leftmost point
		{
			memset(o,0,sizeof(o));//Empty bucket
			int j=i;
			while (a[j].l==i)
			{
				o[y[j]-'a']++;
				j++;
			}//Record the leftmost block in the bucket
			for (j=0;j<x.size();j++)
			{
				if (o[x[j]-'a']) o[x[j]-'a']--;
				else break;
			}//Consider where the leftmost block can go
			s[i][0]=j;//keep for the future
			for (int kk=1;kk<x.size();kk++)
			{
				//Determine whether matching can still be continued
				if (j>=kk) o[x[kk-1]-'a']++;//If yes, the previous invalid operation will be cleared
				else j=kk;//Otherwise, reset the end point
				for (;j<x.size()&&o[x[j]-'a'];j++)
				{
					o[x[j]-'a']--;
				}//Consider where the leftmost block can go
				s[i][kk]=j-kk;//keep for the future
			}
		}
	}

Next set u s i , j us_{i,j} usi,j , is the maximum matching number of S starting from i and T starting from j. in order not to affect other values, we need to enumerate i in reverse order
us equation:
u s i , j = { s l i , j , s l i , j + i − 1 < = r i s l i , j , s l i , j + i = m u s r i + 1 , j − i + 1 + r i + r i − i + 1 , e l s e us_{i,j}= \begin{cases} s_{l_i,j}, s_{l_i,j}+i-1<=r_i\\ s_{l_i,j},s_{l_i,j}+i=m \\ us_{r_i+1,j-i+1+r_i}+r_i-i+1, else \end{cases} usi,j​=⎩⎪⎨⎪⎧​sli​,j​,sli​,j​+i−1<=ri​sli​,j​,sli​,j​+i=musri​+1,j−i+1+ri​​+ri​−i+1,else​
Next, let's explain one by one:
Article 1:

Topics: Programmer