[title record] - the 45th international undergraduate Programming Competition (ICPC) Asian regional competition (Kunming)

Keywords: Algorithm data structure Graph Theory


The 45th international undergraduate Programming Competition (ICPC) Asian regional competition (Kunming)
We only did H, water..
Author's evaluation and partial solution How to evaluate the ICPC Kunming division in 2021?
Partial solution ICPC Kunming travel notes (2021.4.3)

B Chessboard upper and lower bounds minimum cost maximum flow

Title address B Chessboard
Main idea of the title: for an n*m chessboard, you can put black chessboard or white chessboard on it. If you put black chessboard in position (i, j), you will get s b i j sb_{ij} sbij{score, place white pieces and you will get s w i j sw_{ij} swij{score. Only one chess piece can be placed in a grid. We use b i b_i bi represents the number of black pieces in line i, B i B_i Bi = number of black pieces in column i, w i w_i wi indicates the number of white pieces in line i, W i W_i Wi indicates the number of white chessmen in column i. conditions are given
For any line i, b i − w i ϵ [ l i , r i ] b_i-w_i\epsilon[l_i,r_i] bi​−wi​ϵ[li​,ri​]
For any column j, B j − W j ϵ [ L i , R i ] B_j-W_j\epsilon[L_i,R_i] Bj​−Wj​ϵ[Li​,Ri​]
Find the minimum score that can be obtained by satisfying the conditions.
The content of network flow is not something that we can solve. Let's put it aside first
Reference blog 2021 ICPC Kunming Regional Competition B. chess board (upper and lower bounds, minimum cost, maximum flow)

C cities interval dp

Title address C cities
Give an array of length n a i ∈ [ 1 , n ] a_i\in[1,n] ai ∈ [1,n] and no element has appeared more than 15 times,
Now you can change the same interval of a number into another number at a time. Ask, how many times do you operate at least so that there is only one number left in array a.
Idea: reference articles 2021 icpc Kunming C. cities (section dp)
It is an obvious problem of interval dp, but direct dp is not feasible. We need to consider how to reduce the number of enumerations.
definition f [ i ] [ j ] f[i][j] f[i][j] indicates [ i , j ] [i,j] [i,j] minimum number of operations to dye one color
f [ i ] [ j ] = m i n ( f [ i ] [ j − 1 ] , f [ i + 1 ] [ j ] ) + 1 f[i][j]=min(f[i][j-1],f[i+1][j])+1 f[i][j]=min(f[i][j−1],f[i+1][j])+1
But when both ends are equal, we can save one operation
f [ i ] [ j ] = m i n ( f [ i ] [ k ] + f [ k + 1 ] [ j ] ) f[i][j]=min(f[i][k]+f[k+1][j]) f[i][j]=min(f[i][k]+f[k+1][j])
This needs to be met a [ k ] = = a [ j ] a[k]==a[j] a[k]==a[j], dye the left into color K and the right into color j
The title is guaranteed k no more than 15 times
So at first, shrink the dots with the same color, and then transfer them
AC Code:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 5009;
int t,n,a[maxn],col[maxn],f[maxn][maxn],top,nxt;
int pre[maxn],las[maxn];
int main()
{
	cin >> t;
	while( t-- )
	{
		cin >> n; top = 0;
		for(int i=1;i<=n;i++)	cin >> a[i];
		for(int i=2;i<=n;i++)
		{
			if( a[i]==a[i-1] )	continue;
			else	col[++top] = a[i-1];
		}
		memset( pre,0,sizeof pre );
		memset( las,0,sizeof las );
		col[++top] = a[n];
		for(int i=1;i<=top;i++)	
			pre[i] = las[col[i]],las[col[i]] = i;
		memset( f,20,sizeof f );
		for(int i=1;i<=top;i++)	f[i][i] = 0;
		for(int l=2;l<=top;l++)
		for(int i=1;i+l-1<=top;i++)
		{
			int j = i+l-1;
			f[i][j] = min( f[i+1][j],f[i][j-1] )+1;
			for(int k=pre[j];k>=i;k=pre[k])
				f[i][j] = min( f[i][j],f[i][k]+f[k+1][j]);
		}
		cout << f[1][top] << endl;
	}
}

H Hard Calculation simple question

The team leader said there was no need to tidy up. I said no. how can such a difficult problem be incomplete?

Title address H Hard Calculation
The first ICPC held in 2021 will be held once a year, and the nth will be held in that year.
Idea:....
AC Code:

#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
	int n;
    cin >> n;
    cout << 2020+n << endl;
    return 0;
}

I Mr. Main and Windmills computational geometry

Title address I Mr. Main and Windmills
Mr.Main went from s to t by train and passed many windmills.
The train runs in a straight line.
With the running of the train, the position of the windmill will change relatively in the field of vision of Mr.Main.
Now give the coordinates of the windmills. Please find the coordinates of the train when the relative position of the h windmill and other windmills changes k times.
Idea: just take the intersection of the line between two windmill coordinates and the s to t line segment, and then sort it. But we didn't find the intersection of the line and the line segment at that time..
AC Code:

#include<bits/stdc++.h>
 using namespace std;
 const int maxn=1010;
 const double eps=1e-8;
 int n,m;
 double xs,ys,xt,yt; 
 int sgn (double x) {
     if (fabs(x)<eps) return 0;
     else if (x<0) return -1;
     else return 1;
 }
 double x[maxn],y[maxn];
 vector<pair<double,double> > p[maxn];
 //The intersection of the line formed by each point and all remaining points with the bus
 pair<double,double> jd (double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4) {
     if (x1==x2&&y1==y2) return make_pair(1e18,1e18);
     //Intersection of the straight line composed of (x1,y1),(x2,y2) and the straight line composed of (x3,y3),(x4,y4)
     double k1=(x1==x2?1e18:(y1-y2)/(x1-x2));
     double k2=(y1==y2?1e18:(y3-y4)/(x3-x4));
     if (sgn(k1-k2)==0) return make_pair(1e18,1e18);
     //k1 is 1e18, k2 is not. The answer is x1*k2+b2
     if (k1==1e18) {
         return make_pair(x1,x1*k2+y3-k2*x3);
     } 
     else if (k2==1e18) {
         return make_pair(x2,x2*k1+y1-k1*x1);
     }
     double b1=y1-k1*x1;
     double b2=y3-k2*x3;
     double x=(b2-b1)/(k1-k2);
     double y=k1*x+b1;
     return make_pair(x,y);
 }
 int cmp (pair<double,double> x,pair<double,double> y) {
     if (sgn(x.first-y.first)!=0) {
         return sgn(x.first-y.first)<0;
     }
     else {
         return sgn(x.second-y.second)<0;
     }
 } 
 int main () {
     scanf("%d%d",&n,&m);
     scanf("%lf%lf%lf%lf",&xs,&ys,&xt,&yt);
     for (int i=1;i<=n;i++) scanf("%lf%lf",x+i,y+i);
     for (int i=1;i<=n;i++) {
         for (int j=1;j<=n;j++) {
             if (i==j) continue;
             pair<double,double> it=jd(x[i],y[i],x[j],y[j],xs,ys,xt,yt); 
             if (it.first==1e18) continue;//No intersection
             if (sgn(it.first-min(xs,xt))<0||sgn(it.first-max(xs,xt))>0||sgn(it.second-min(ys,yt))<0||sgn(it.second-max(ys,yt))>0) continue;//The intersection is outside the line segment
             p[i].push_back(it); 
         }
         if (xs<xt) sort(p[i].begin(),p[i].end(),cmp);
         else if (xs>xt) sort(p[i].rbegin(),p[i].rend(),cmp);
         else if (ys<yt) sort(p[i].begin(),p[i].end(),cmp);
         else sort(p[i].rbegin(),p[i].rend(),cmp);
     }
     while (m--) {
         int h,t;
         scanf("%d%d",&h,&t);
         //printf("%d\n",p[h].size());
         if (t>p[h].size()) {
             printf("-1\n");
             continue;
         }
         printf("%.10f %.10f\n",p[h][t-1].first,p[h][t-1].second);
     }
 }

Posted by bigbillhill on Thu, 18 Nov 2021 03:20:36 -0800