The 16th programming competition of Hunan University

Posted by perrohunter on Sun, 16 Jan 2022 13:50:04 +0100

The 16th programming competition of Hunan University

Game link

Question A

Meaning:
Judge right angles, acute angles, obtuse angles and triangles for three coordinate points.

analysis:
Compare the two sides to determine whether there are duplicate points, calculate the length of the three sides, and then judge whether they are collinear (the collinear condition is that the sum of the two sides is equal to the third side). Finally, the cosine theorem is used to judge the angle.

Question B

Meaning:
Initially, there is an apple with N people. There are two operations:

  1. Turn all apples into ten times, that is, K - > 10 * K
  2. Turn one of the apples into x, that is, K - > k-1 + X

Given N and x, ask at least how many steps can make the apple in your hand an integral multiple of N.
analysis:
In BFS search, after selecting two operations at each step, the number of apples is mod N (the control range is [0,N), and this point is marked. The first point searched is 0, which is the answer.
code:

#include <iostream>
#include <queue>
using namespace std;
const int N=1e6+10;
struct node
{
	int rank;
	int num;
};
bool B[N];
int main()
{
	long long n,x;
	cin>>n>>x;
	if(n==1)
	{
		cout<<0<<endl;
		return 0;
	}
	queue<node> que;
	node a;
	a.num=1;a.rank=0;
	que.push(a);B[1]=true;
	while(!que.empty())
	{
		node p,q;
		a=que.front();que.pop();
		p.rank=q.rank=a.rank+1;
		int s=a.num,r=a.rank;
		p.num=10*s%n;q.num=(s+x-1)%n;
		if(p.num==0||q.num==0)
		{
			cout<<r+1<<endl;
			return 0;
		}
		else
		{
			if(!B[p.num]) que.push(p),B[p.num]=true;
			if(!B[q.num]) que.push(q),B[q.num]=true;
		}
	}
	cout<<-1<<endl;
	return 0;
}

Question D

Meaning:
There is a team, you are in the m, and then the team will be divided into n windows. The one in front of you is still in front of you. Ask your expectation of ranking in the window at the end. The title is given n and m.
analysis:
A hateful math problem can only be understood by reading the solution
Roughly set the expected value E(m) of M personal period, with

  • E(1)=1
  • E(m)=E(m-1)+1/n

When ranking m, remove the first person. At this time, the situation is similar when ranking m-1. At this time, the probability of the removed person ahead of you is 1/n.
Expand to get the answer E (m) = (m-1) / n + 1

Question F

Meaning:
Given a,b,c, find a + B + C 2 ^ 62 < = a, B < = 2 ^ 63 0 < = C < = 2
analysis:
The maximum value of the addition of three numbers is 2 ^ 64 + 2. The range of unsigned long long is 0 ~ 2 ^ 64-1. If the maximum value is exceeded, start again from 0.
code:

#include <iostream>
using namespace std;
int main()
{
	unsigned long long a,b,c,sum;
	cin>>a>>b>>c;
	sum=a+b;sum+=c;
	if(sum<10)
		cout<<"1844674407370955161"<<6+sum<<endl;
	else cout<<sum<<endl;
	return 0; //92233720368547758007
}

Question I

Meaning:
There are two balls with n floors. The two balls have the same hardness. If they are dropped from above a certain floor, they will break. Ask the number of times to find the largest floor that can not break the ball in the worst case. Given t and n
analysis:
Math again?, I don't know why, but it looks right
Set the minimum number of times as T. the first choice is on the T floor. If it is broken, the answer is 1~t-1, and the other ball tries from 1 to t-1. If it is not broken, throw it from the t+t-1 floor (equivalent to repeating with the T floor as the 0 floor). Let S(t)=1+2+3 +... + T, and finally use dichotomy to find the minimum t so that s (T) > = n
code:

#include <iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long n;
		cin>>n;
		long long l=1,r=2e9;
		while(l<r)
		{
			long long mid=l+r>>1;
			if(mid*(mid+1)/2LL>=n) r=mid;
			else l=mid+1;
		}
		cout<<l<<endl;
	}
	return 0;
}

L question

Meaning:
Six kinds of water pipes are shown to you. Ask whether the upper left to the lower right are connected
analysis:
The simulation question vector can be saved as a two-dimensional map
code:

#include <iostream>
#include <vector>
using namespace std;
int n,m;
int fx[5]={0,0,-1,1,0};
int fy[5]={0,-1,0,0,1};//×ó ÉÏ ÏÂ ÓÒ 
vector<vector<int> > vec;
vector<vector<int> > B;
vector<vector<int> > lt;
bool sf(int f,int x,int y)
{
	int now=vec[x][y];
	for(int i=0;i<lt[now].size();i++)
	{
		int ff=lt[now][i];
		//cout<<ff<<endl;
		if(ff+f==5)return true;
	}
	return false;
}
void dfs(int x,int y,int pre)
{
	B[x][y]=1;
	//cout<<x<<' '<<y<<' '<<pre<<endl;
	int now=vec[x][y];
	for(int i=0;i<lt[now].size();i++)
	{
		int f=lt[now][i];//cout<<f<<endl;
		int xx=x+fx[f],yy=y+fy[f];
		if(xx<=n&&xx>=1&&yy<=m&&yy>=1)
			if(f!=pre&&!B[xx][yy])
				if(sf(f,xx,yy))dfs(xx,yy,5-f);
	}
	return;
}
int main()
{
	
	cin>>n>>m;
	vec.resize(n+10),B.resize(n+10);
	for(int i=1;i<=n;i++)
	{
		vec[i].resize(m+2);
		B[i].resize(m+2);
		for(int j=1;j<=m;j++)
			cin>>vec[i][j],B[i][j]=0;
	}
	lt.resize(7);
	lt[1].push_back(2),lt[1].push_back(3);
	lt[2].push_back(1),lt[2].push_back(4);
	lt[3].push_back(3),lt[3].push_back(4);
	lt[4].push_back(1),lt[4].push_back(2);
	lt[5].push_back(1),lt[5].push_back(2),lt[5].push_back(4);
	lt[6].push_back(1),lt[6].push_back(3),lt[6].push_back(4);
	vec[1][0]=2;
	dfs(1,0,1);
	int k=vec[n][m];
	if((k==2||k==5||k==6)&&B[n][m])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
		
}