Problem A Forever 0.5(推理构造)

来源:互联网 发布:软件项目计划书 编辑:程序博客网 时间:2024/04/30 22:54


题目:http://acm.fzu.edu.cn/problem.php?pid=2140

题意:

题目大意:给出n,要求找出n个点,满足: 
1)任意两点间的距离不超过1; 
2)每个点与(0,0)点的距离不超过1; 
3)有n对点之间的距离刚好为1; 
4)n个点组成的多边形面积大于0.5; 
5)n个点组成的多边形面积小于0.75;

思路:只要有4个点以上就是,构造时先找出四个点,再在半径为1的圆上找点就行。

很巧妙的一道题目呀、、、、

按 Ctrl+C 复制代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;


double x[110], y[110];
void slo()
{
    x[0] = 0; y[0] = 0;
    x[1] = 1; y[1] = 0;
    x[2] = 0.5; y[2] = sqrt(1-0.5*0.5);
    x[3] = 0.5; y[3] = y[2]-1;
    for(int i = 4; i < 102; i++)
    {
        x[i] = 1-0.001*i;
        y[i] = sqrt(1-x[i]*x[i]);
    }
}
int main()
{
    int t, n;
    cin>>t;
    slo();
    while(t--)
    {
        cin>>n;
        if(n<=3)
            cout<<"No"<<endl;
        else
        {
            cout<<"Yes"<<endl;
            for(int i = 0; i < n; i++)
                printf("%.6lf %.6lf\n", x[i], y[i]);
        }
    }
    return 0;
}
按 Ctrl+C 复制代码

0 0
原创粉丝点击