HihoCoder - 1429 Problem H. A New Ground Heating Device(K次圆并

传送门

Problem

A brand new photosensitive ground heating device is under developing.

This time, to test these devices and help local farmers, engineers placed several devices on the ground in a greenhouse. (You can assume the ground of the greenhouse as a plane and the height of all devices are zero)

There is only a light source in the greenhouse. Its coordinate at the plane must be (0,0),but you can put it at any height above the ground(or on the ground) as you want.

The effective warming radius of the  i th device is  WLi×Zi  , among which  w  is the power of the light source,  Li  is the distance between light source and the  i th device, while owing to different degree of wear and tear, photoresistance factor of each device,  Zi , may be different.

The winter is so harsh that a piece of land in this greenhouse is suitable for planting only when it is heated by at least  K  devices at the same time.

Considering the efficiency of production, farmers require that the area of arable land should be greater than  S .

Engineers wonder, to satisfy the heating demand raised by farmers, what is the maximum height of the light source.

主要意思就是 n 个机器,每个机器制热的覆盖半径是  WLi×Zi  ,其中 W 和  Zi  均为定值, Li  指机器与 light source 的三维距离(机器的坐标已固定,且高度一定为 0 ,light source 的横纵坐标均为 0, 高度可变)。求 light source 可行的最高高度,使得满足至少有 S 的面积能被至少 K 个机器制热半径覆盖。

解题思路

二分枚举 light source 的高度,对每次产生的高度判断被  K  个机器覆盖的面积是否大于等于 S。

对于求 K 机器覆盖的面积,套用 K 次圆并的模板。

:cry: 模板题。

//china no.1
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <bitset>
using namespace std;

#define pi acos(-1)
#define PI acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
#define db double
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-1,0,1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const int maxn=1e3+10;
const int maxx=1e6+100;
const double EPS=1e-8;
const double eps=1e-8;
const int mod=10000007;
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
template <class T>
inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}
while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}

inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;
while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}
else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}
if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}
if(IsN) num=-num;return true;}

void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}
void print(LL a){ Out(a),puts("");}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
//cerr << "run time is " << clock() << endl;



db sqr(db x)
{
   return x*x;
}
int dcmp(double x)
{
    if(fabs(x) < EPS) return 0;
    else return x < 0 ? -1 : 1;
}


struct Circle
{
    double x, y, r, angle;
    int d;
    Circle(){}
    Circle(double xx, double yy, double ang = 0, int t = 0)
    {
        x = xx;  y = yy;  angle = ang;  d = t;
    }
    void get()
    {
        scanf("%lf%lf%lf", &x, &y, &r);
        d = 1;
    }
};

Circle cir[maxn],tp[maxn*2];
double area[maxn];

double dis(Circle a,Circle b)
{
    return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}

double cross(Circle p0,Circle p1,Circle p2)
{
    return (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x);
}
//圆相交
int CirCrossCir(Circle p1, double r1,Circle p2, double r2,Circle &cp1,Circle &cp2)
{
    double mx = p2.x - p1.x, sx = p2.x + p1.x, mx2 = mx * mx;
    double my = p2.y - p1.y, sy = p2.y + p1.y, my2 = my * my;
    double sq = mx2 + my2, d = -(sq - sqr(r1 - r2)) * (sq - sqr(r1 + r2));
    if (d + eps < 0) return 0; if (d < eps) d = 0; else d = sqrt(d);
    double x = mx * ((r1 + r2) * (r1 - r2) + mx * sx) + sx * my2;
    double y = my * ((r1 + r2) * (r1 - r2) + my * sy) + sy * mx2;
    double dx = mx * d, dy = my * d; sq *= 2;
    cp1.x = (x - dy) / sq; cp1.y = (y + dx) / sq;
    cp2.x = (x + dy) / sq; cp2.y = (y - dx) / sq;
    if (d > eps) return 2; else return 1;
}
bool circmp(const Circle& u, const Circle& v)
{
    return dcmp(u.r - v.r) < 0;
}

bool cmp(const Circle& u, const Circle& v)
{
    if (dcmp(u.angle - v.angle)) return u.angle < v.angle;
    return u.d > v.d;
}
//0.5*r*r*(K-sin(K))
double calc(Circle cir,Circle cp1,Circle cp2)
{
    double ans = (cp2.angle - cp1.angle) * sqr(cir.r)
        - cross(cir, cp1, cp2) + cross(Circle(0, 0), cp1, cp2);
    return ans / 2;
}

void CirUnion(Circle cir[], int n)
{
    Circle cp1, cp2;
    sort(cir, cir + n, circmp);
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            if (dcmp(dis(cir[i], cir[j]) + cir[i].r - cir[j].r) <= 0)
                cir[i].d++;
    for (int i = 0; i < n; ++i)
    {
        int tn = 0, cnt = 0;
        for (int j = 0; j < n; ++j)
        {
            if (i == j) continue;
            if (CirCrossCir(cir[i], cir[i].r, cir[j], cir[j].r,
                cp2, cp1) < 2) continue;
            cp1.angle = atan2(cp1.y - cir[i].y, cp1.x - cir[i].x);
            cp2.angle = atan2(cp2.y - cir[i].y, cp2.x - cir[i].x);
            cp1.d = 1;    tp[tn++] = cp1;
            cp2.d = -1;   tp[tn++] = cp2;
            if (dcmp(cp1.angle - cp2.angle) > 0) cnt++;
        }
        tp[tn++] = Circle(cir[i].x - cir[i].r, cir[i].y, pi, -cnt);
        tp[tn++] = Circle(cir[i].x - cir[i].r, cir[i].y, -pi, cnt);
        sort(tp, tp + tn, cmp);
        int p, s = cir[i].d + tp[0].d;
        for (int j = 1; j < tn; ++j)
        {
            p = s;  s += tp[j].d;
            area[p] += calc(cir[i], tp[j - 1], tp[j]);
        }
    }
}
int w,k,s,n,t;
int x[maxn],y[maxn];
db z[maxn];
db getR(db x,db y,db h,db z)
{
    db d=sqrt(x*x+y*y+h*h);
    return w*1.0/d/z;
}

int check(db h)
{
    me(cir,0);
    for(int i=0;i<n;i++)
    {
        cir[i].x=x[i];
        cir[i].y=y[i];
        cir[i].d=1;
        cir[i].r=getR(x[i],y[i],h,z[i]);
    }
    me(area,0);
    CirUnion(cir,n);
    if(dcmp(area[k]-s)>=0) return 1;
    return 0;
}
int main()
{
    //freopen( "in.txt" , "r" , stdin );
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d %d %d %d", &n, &w, &k, &s);
        for(int i=0;i<n;i++)
            scanf("%d %d %lf", &x[i], &y[i], &z[i]);
        if(check(500))
        {
            printf("Oops!\n");
        }
        else if(!check(0))
        {
            printf("No solution!\n");
        }
        else
        {
            double l = 0, r = 500, mid;
            int len=50;
            W(len--)
            {
                mid = (l+r) / 2;
                if(check(mid)) l = mid+1;
                else  r = mid-1;
            }
            printf("%.4f\n",l-1);
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 根据提供的信息,这个问题似乎是和Pentaho中的插件存储库相关的访问问题。 "Pentaho" 是一种用于数据集成和业务智能(BI)的开源工具。而 "/@pentaho/di-plugin-repositories@8.3.0.0-371/index.h" 是指特定版本的一个插件存储库的索引文件。 如果出现 "spoon problem accessing /@pentaho/di-plugin-repositories@8.3.0.0-371/index.h" 的错误信息,可能是由于以下几个原因之一: 1. 插件存储库不可访问:这可能是由于网络连接问题或存储库服务器错误引起的。你可以尝试检查网络连接是否正常,或者联系Pentaho支持团队获取有关存储库服务器状态的更多信息。 2. 插件存储库路径错误:如果路径指定不正确,或者文件路径被更改或删除,就可能无法访问索引文件。你可以验证索引文件的路径是否正确,并确保文件存在。 3. 插件存储库版本不匹配:错误信息中提到了特定的插件存储库版本号(8.3.0.0-371),可能是由于Pentaho版本与该插件存储库版本不兼容导致的。你可以尝试与Pentaho版本对应的插件存储库版本,或者升级Pentaho到与该插件存储库版本兼容的版本。 综上所述,通过验证网络连接、检查存储库路径和确保兼容的Pentaho版本,你可以尝试解决这个问题。如果问题仍然存在,建议联系相关技术支持人员获取进一步的帮助。 ### 回答2: spoon问题访问 /@pentaho/di-plugin-repositories@8.3.0.0-371/index.h的原因可能有以下几种: 1. 网络问题:如果你的电脑无法访问这个地址,可能是因为网络连接出现了问题。你可以尝试重新连接到网络或者使用其他网络环境进行尝试。 2. 路径错误:可能是路径设置错误导致无法访问。你可以检查一下路径是否正确,并确认文件或文件夹是否存在。 3. 权限问题:有时候你可能没有访问该文件或文件夹的权限,导致无法访问。你可以尝试使用管理员权限或者联系系统管理员解决权限问题。 4. 插件版本不匹配:如果你的Spoon版本与这个插件版本不兼容,可能会引发访问问题。你可以尝试更新Spoon或找到与你当前版本兼容的插件。 如果以上解决方法都无法解决问题,建议你查看详细的错误信息或者寻求专业的技术支持来解决这个问题。希望能对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值