2019 CCPC-Jiangxi Provincial Competition (Repeat Competition) Part of the Questions

Keywords: Graph Theory

Catalog

B - Wave

C - String

D - Traffic

F - Budget

G - Worker

H - Class

B - Wave

Topic:

Given a sequence of n integers ranging from 1 to c, find a subsequence that has the same number on even digits, the same number on odd digits, and different numbers on even and odd digits.

Output the length of the longest subsequence that meets the requirements.

Ideas:

Simple DP, setYes   Ending,   For the longest legal wave of the previous number,

There is a state transfer equation:
.

AC code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int dp[110][110];
int a[maxn];
int main()
{
    int n,c,x;
    while(cin>>n>>c)
    {
        memset(dp,0,sizeof(dp));
        for(int i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        int ans=0;
        for(int i=1; i<=c; i++)
        {
            if(a[1]==i)
            {
                dp[a[1]][i]=0;
            }
            else
            {
                dp[a[1]][i]=1;
            }
        }
        for(int i=2; i<=n; i++)
        {
            for(int j=1; j<=c; j++)
            {
                if(a[i]==j)
                    dp[a[i]][j]=0;
                else
                    dp[a[i]][j]=dp[j][a[i]]+1;
                ans=max(ans,dp[a[i]][j]);
            }
        }


        cout<<ans<<endl;
    }
}

C - String

Title: A string of length n that randomly takes one character from the string at a time (can be replaced). Four times, ask how many chances are there for a string to be composed in the order in which the characters are taken to be "avin"?
Please output the simplest fractional form. If the probability is 0, the output is "0/1".

Ideas: Count the number of occurrences of each character, and calculate the probability according to the principle of multiplication. The output is in the simplest fractional form, and the denominator of the molecule is divided by its maximum common factor.

AC code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e3+10;
ll a[maxn];
ll b[maxn];
map<char,int> mp;
int main()
{
    int n;
    while(cin>>n)
    {
        mp.clear();
        string s;
        cin>>s;
        for(int i=0;i<n;i++)
            mp[s[i]]++;
        ll y=n*n*n*n;
        ll x=mp['a']*mp['v']*mp['i']*mp['n'];
        if(x==0) cout<<"0/1"<<endl;
        else
        {
            ll z=__gcd(x,y);
            x/=z;
            y/=z;
            cout<<x<<"/"<<y<<endl;
        }
    }
}

D - Traffic

Topic:

There is an intersection, divided into east-west and North-South directions. Vehicles will pass in both directions at different time points. If both directions come in at the same time point, traffic accidents will occur to avoid accidents. Thus, it is stipulated that east-west direction vehicles will have priority in driving, delaying the transit time of north-south direction vehicles backward (overall delay), and finding a minimum delay time so that the east-west direction and north-south direction vehicles will not overlap with the transit time.

Ideas:

East-West vehicle wait time a[j], north-south b[i], we want to find the minimum delay times ans so that. Mark an array of a, traverse the B array, and if the current b[i]+ans collides with the elements in a, then ans++.

AC code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
int a[maxn],b[maxn],vis[maxn];
int main()
{
	int n,m;
	while(cin>>n>>m)
    {
		memset(vis,0,sizeof(vis));
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			vis[a[i]]=1;
		}
		for(int i=0;i<m;i++)
		{
			cin>>b[i];
		}
		int ans=0;
		for(int i=0;i<m;i++)
		{
			if(vis[b[i]+ans]==1)
			{
				i=0;
				ans++;
			}
		}
		cout<<ans<<endl;
	}

}

F - Budget

Title: Round three decimal places to two decimal places and determine what the error is.

Idea: Enter the number as a string and use theJudge the last decimal:

Set b to the last decimal (that is, the third after the decimal point)

(1) If b<=4, add-b*0.001 to the answer.

  (2) If b>=5, then the answer is (10-b)*0.001.

AC code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
int a[maxn],b[maxn],vis[maxn];
int main()
{
	int n;
	while(cin>>n)
	{
		string a;
		double sum=0;
		for(int i=0;i<n;i++)
		{
			cin>>a;
			int x=a.length();
			if(a[x-1]-'0'>=5)
			{
				sum+=((10-(a[x-1]-'0'))*0.001);
			}
			else sum-=((a[x-1]-'0')*0.001);
		}
		printf("%.3lf\n",sum);
	}
}


G - Worker

Topic: There are n workshops and m workers. Workers working in the first workshop can complete Tasks. Please come up with a plan for assigning workers so that the total number of tasks completed in each workshop is the same. Output "NO" without a solution, you can assign the output "YES" and the number of workers in each workshop.

Ideas:

The proportion of people assigned to each warehouse should be

Unfortunately they are not integers, so we ordered(M is the smallest common multiple of the array)

The proportion of people assigned to each warehouse should be

Then warehouse i I needsPerson, if the value is not an integer, then NO is output.

AC code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
ll a[maxn],b[maxn];
ll gcd(int aa,int bb)
{
	return bb==0?aa:gcd(bb,aa%bb);
}
ll lcm(int aa,int bb)
{
	return aa/gcd(aa,bb)*bb;
}
int main()
{
	ll n,m;
	while(cin>>n>>m)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		ll sum=1;
		ll sum1=0;
		for(ll i=0;i<n;i++)
		{
			cin>>a[i];
			sum = lcm(sum,a[i]);
		}
		for(ll i=0;i<n;i++)
		{
			b[i]=sum/a[i];
			sum1+=b[i];
		}
		if(m%sum1==0)
		{
			cout<<"Yes"<<endl;
			for(ll i=0;i<n;i++)
			{
				if(i==0)
				{
				    cout<<(m/sum1)*b[i];
				}
				else
				{
				    cout<<" "<<(m/sum1)*b[i];
				}
			}
			cout<<endl; 
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
}


H - Class

Topic:

Ideas:

be

 

AC code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
     int x,y;
     cin>>x>>y;
     cout<<(x*x-y*y)/4<<endl;
}

Posted by adredz on Wed, 10 Nov 2021 01:43:01 -0800