此文章可以使用目錄功能喲↑(點擊上方[+])
FZU Problem 2140 Forever 0.5
Accept: 0 Submit: 0 Special Judge
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Given an integer N, your task is to judge whether there exist N points in the plane such that satisfy the following conditions:
1. The distance between any two points is no greater than 1.0.
2. The distance between any point and the origin (0,0) is no greater than 1.0.
3. There are exactly N pairs of the points that their distance is exactly 1.0.
4. The area of the convex hull constituted by these N points is no less than 0.5.
5. The area of the convex hull constituted by these N points is no greater than 0.75.
Input
The first line of the date is an integer T, which is the number of the text cases.
Then T cases follow, each contains an integer N described above.
1 <= T <= 100, 1 <= N <= 100
Output
For each case, output “Yes” if this kind of set of points exists, then output N lines described these N points with its coordinate. Make true that each coordinate of your output should be a real number with AT MOST 6 digits after decimal point.
Your answer will be accepted if your absolute error for each number is no more than 10-4.
Otherwise just output “No”.
See the sample input and output for more details.
Sample Input
2
3
5
Sample Output
No
Yes
0.000000 0.525731
-0.500000 0.162460
-0.309017 -0.425325
0.309017 -0.425325
0.500000 0.162460
Hint
This problem is special judge.
Problem Idea
解題思路:
【題意】
給你一個整數n,你的任務是判斷平面上是否存在n個點滿足下列條件:
1.任意兩點間的距離不超過1.0
2.任意一點與原點(0,0)的距離不超過1.0
3.恰好存在n對點,每對中的兩點間距離恰好爲1.0
4.n個點構成的凸包面積不小於0.5
5.n個點構成的凸包面積不大於0.75
【類型】
計算幾何,構造(考查思維)
【分析】
剛開始看這題的時候感覺有些難度,但是其實只要稍微分析一下,答案便會浮出水面
首先,我們可以根據樣例判斷出n=2和n=3時,爲什麼是不存在這樣的n個點的
很簡單
當n=2時,無論怎麼構造,都不滿足條件3,因爲兩個點最多隻能組成一對點,而條件3要求恰好有n對,顯然無法辦到
當n=3時,最多隻能組成3對,恰好達到條件3的數量限定,這樣子的話,那n個點構成的凸包只有一種情況,如下:
該情況下,凸包面積爲(√3)/4≈0.433<0.5
故不滿足條件4
這時,我們又可以從樣例中看到n=5時,是存在這n個點的
且除第一個點外,剩下的點似乎又關於y軸對稱
可見,此題必定有什麼入手點
考慮到恰好存在n對點,每對點的距離恰好爲1.0這個條件
我們應該優先考慮如何構造能夠保證恰好只有n對點距離爲1.0
因爲當n>3時,n個點能組成的點對已經超過n對
本人最先考慮到的構造方法是這樣的
但是這樣貌似只有n-1對距離爲1.0的點對
再想想,對了,怎麼忘了n=3時的那種情況呢,只要保證上圖中P2和Pn的距離是1.0不就恰好有n對距離爲1.0的點對了?
嗯,不錯,再想想這種情況會不會超過凸包面積的上界
我們可以知道的是,P2與Pn之間的點越多,這個凸包越接近扇形
那這個扇形必定是面積最大的時候,由於扇形角度是60°,故可以求得扇形面積是1/6圓面積,爲π/6≈0.524<0.75,上界顯然可以
那我只要保證下界滿足就可以了,那我們從n=4開始考慮,理想的構造方法應該是這樣的
此時凸包面積恰好爲1.0*1.0/2=0.5,符合條件
那當n>4時如何擺放其他點呢?要不都和P4重合吧,於是此題得到完美解決
【時間複雜度&&優化】
O(1)
題目鏈接→FZU Problem 2140 Forever 0.5
Source Code
/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 100005;
const int M = 100005;
const int inf = 1000000007;
const int mod = 1000000007;
int main()
{
int t,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n<4)
{
puts("No");
continue;
}
puts("Yes");
printf("%.6f %.6f\n",0.0,0.0);
printf("%.6f %.6f\n",0.5,0.5*sqrt(3.0));
printf("%.6f %.6f\n",-0.5,0.5*sqrt(3.0));
for(i=3;i<n;i++)
printf("%.6f %.6f\n",0.0,1.0);
}
return 0;
}
菜鳥成長記