1245. Pictures
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Artist Ivanov (not the famous Ivanov who painted "Christ's apparition to people", but one of the many namesakes) once managed to rent inexpensively an excellent studio. Alas, as he soon discovered, the inexpensiveness was caused by objective reasons. A murder happened long ago in the house where he rented the room, and now the ghost living in the house each night renews blood spots on the walls of all the rooms. Ivanov's studio did not escape this damnation.
Nevertheless, being a creative person, Ivanov quickly found a simple solution to the problem. He decided to paint one or two pictures and hang them on the (single) wall where the spots appear each night so that the spots would be covered by the pictures. Of course, he does not want to spend too much time doing this work. That is why he plans to use not more than two pictures and wants the total area of the pictures to be minimal.
All the blood spots are circles. Each picture has a rectangular form with sides parallel to the axes, and the minimally possible size of a picture in each of the dimensions is 100 millimeters. If it is necessary to paint two pictures, then they should be hanged to the wall without overlaying. Each spot must be covered by exactly one picture.
Input
The first line contains the number of the spots N, 0 < N ≤ 1000. Each of the next N lines contains the description of the corresponding spot. A spot is described by three positive integers; they are the radius of the spot and the Cartesian coordinates of the center of the spot. Everything is measured in millimeters and all these numbers do not exceed 10000.
Output
Output the minimal total area (in square millimeters) of the pictures (not more than two) necessary to cover all the spots.
Sample
input | output |
---|---|
3 |
40000 |
Problem Author: Alexander Petrov (text — Leonid Volkov)
Problem Source: Ural State University Personal Programming Contest, March 1, 2003
Problem Source: Ural State University Personal Programming Contest, March 1, 2003
Tags: none (hide tags for unsolved problems)
Difficulty: 898
题意:平面上有一些圆,半径ri,圆心(xi,yi),问用不超过两个矩阵覆盖他们的最小面积。注意:一个圆不能被两个矩形覆盖。
分析:显然,因为一个圆不能被两个矩形覆盖,瞬间变的简单。
矩形边界必为某个圆的上下左右的切线。
枚举即可。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = , M = ;
struct Point
{
int x, y, r; inline void Read()
{
r = Getint();
x = Getint();
y = Getint();
} inline bool operator <(const Point &A) const
{
return x < A.x;
}
} Arr[N];
int n;
int LU[N], LD[N], RU[N], RD[N], Left[N], Right[N];
int Ans = MIT; inline void Input()
{
n = Getint();
For(i, , n) Arr[i].Read();
} inline void Work()
{
sort(Arr + , Arr + + n);
Right[] = -INF, LD[] = INF, LU[] = -INF;
For(i, , n)
{
Right[i] = max(Right[i - ], Arr[i].x + Arr[i].r);
LU[i] = max(LU[i - ], Arr[i].y + Arr[i].r);
LD[i] = min(LD[i - ], Arr[i].y - Arr[i].r);
}
Left[n + ] = INF, RD[n + ] = INF, RU[n + ] = -INF;
Ford(i, n, )
{
Left[i] = min(Left[i + ], Arr[i].x - Arr[i].r);
RU[i] = max(RU[i + ], Arr[i].y + Arr[i].r);
RD[i] = min(RD[i + ], Arr[i].y - Arr[i].r);
} For(i, , n)
if(Right[i - ] <= Left[i])
Ans = min(Ans,
max(M, Right[i - ] - Left[]) * max(M, LU[i - ] - LD[i - ]) +
max(M, Right[n] - Left[i]) * max(M, RU[i] - RD[i]));
} inline void Solve()
{
Work();
For(i, , n) swap(Arr[i].x, Arr[i].y);
Work(); Ans = min(Ans, max(M, Right[n] - Left[]) * max(M, LU[n] - LD[n])); printf("%d\n", Ans);
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("D");
#endif
Input();
Solve();
return ;
}