Poj Kadj Squares (Geometry)

  • Kadj Squares

  • The meaning of the question is
    to give the side lengths of N squares, rotate 45 degrees counterclockwise along the lower left vertex, and one vertex is on the x-axis. One vertex of the first square is placed on the y-axis, from left to right at a time. The sides are allowed to overlap but the areas are not allowed to intersect. Ask those squares to be seen when looking down from the top.

  • Idea
    At the beginning, I first obtained the coordinates of b, and then knew the coordinates of the left and right endpoints, and then judged whether the rectangle was covered. I don't know if it was written wrong or the accuracy was stuck. Later found that we can expand the side length by 2 \sqrt 22 At this time, the left and right endpoints are all integers. Then judge whether it is covered according to the left and right endpoints.
    How to find the left end of a rectangle

  • Code

#pragma GCC optimize(2)
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
//#include<cmath> 

using namespace std;

typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
#define pi acos(-1.0)
#define e exp(1.0)
#define pb push_back
#define mk make_pair
#define fir first
#define sec second
#define scf scanf
#define prf printf
#define sqt sqrt(2.0)
typedef pair<ll,ll> pa;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int MAX_N=55;
int N;
int a[MAX_N],l[MAX_N],r[MAX_N];
int abs(int n){
    
    
	return n>0?n:-n;
} 
int main()
{
    
    
//  freopen(".../.txt","w",stdout);
//  freopen(".../.txt","r",stdin);
	ios::sync_with_stdio(false);
	while(cin>>N&&N){
    
    
		int i,j,k,L,R;
		for(i=1;i<=N;i++)
		cin>>a[i];
		for(i=1;i<=N;i++){
    
    
			L=0;
			for(j=1;j<i;j++){
    
    
				L=max(L,r[j]-abs(a[i]-a[j]));
			}
			l[i]=L;
			r[i]=L+2*a[i];
		} 
		for(i=1;i<=N;i++){
    
    
			L=l[i];
			R=r[i];			
			for(j=1;j<=N;j++){
    
    
				if(i==j)
				continue;
				if(j<i)//左边的正方形能覆盖的最大坐标 
				L=max(L,r[j]);
				else//右边的正方形能覆盖的最小坐标 
				R=min(R,l[j]);
			}
			if(L<R)
			cout<<i<<' ';
		}
		cout<<endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_43311695/article/details/108964386