武大OJ 612. Catch the sheep

Description

Old Sama is a great and powerful magician in the word.

 

One day, a little girl, Anny, touched Sama’s crystal and broke into his magic  2D space. However, Sama is very amiable. So he wanted to send Anny back to the real world instead of trapping her and he also wanted to teach Anny a lesson ‘Never touch others’ things without asking especially for a great magician’.

 

So Sama told Anny there were  N sheep in the space and each of them was running in a  counter clockwise circular motion with  a constant speed u, which was less than 1 (Sama is kind, isn’t he?). Only after Anny caught all of the sheep, she could leave.

 

Anny was scarred and she wanted to leave as soon as possible.  Her speed is exactly 1. Now she wondered how soon can she leave?

 

Input

The input consists of several test cases.
The first line consists of one integer T (T <= 30), meaning the number of test cases.
For each test cases:
The first line consists of integer n (n<=10).
In the next n lines, the i-th line consists of four real number, xi, yi, ri, ui, describing the motion of each sheep (|xi|, |yi| <= 100, 0<=ri<=100, 0<ui<1). (xi, yi) means the coordinate of the center of the circle, ri means the radius of the circle, and ui means the speed of the sheep i.
You should know Anny always started in (0,0). And the sheep always started in (xi+ri, yi).

Output

For each test case, output one line with one real number with 6 decimal places meaning the minimum time Anny could leave without any space.

Sample Input

1
1
11 0 1 0.31415926535897932384626433832795 

Sample Output

10.000000


本题的难点是根据当前坐标和时间求与第i只羊的最短交汇时间,转移的耗时显然是满足二分性质的,知道当前位置,当前时刻,下一只羊的信息就能够通过二分求得耗时
状态压缩Dp,dp[status][i]表示抓了status状态表示的羊最后抓的羊的编号为i
其实用爆搜应该也可以
时间复杂度:?(??^2∗2^?)(k是二分迭代次数)

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

typedef struct{
    double x,y,time;
    bool isCal;
}Status;
typedef struct{
    double x,y,r,u;
}Point;

Status f[1<<11][10];
Point p[10];
int t,n;

Status calcuateTimeAndXY(double x,double y,double time,int num){
    double left=0,right=1000,mid;
    double u=p[num].u;
    double r=p[num].r;
    double x0=p[num].x;
    double y0=p[num].y;
    
    double x2,y2;
    
    while(fabs(right-left)>1e-9)
    {
        mid=(right+left)/2.0;
        double t=mid+time;
        double theta=(u*t-floor(u*t/(2*M_PI*r))*2*M_PI*r)/r;
        x2=x0+r*cos(theta);
        y2=y0+r*sin(theta);
        
        if((x2-x)*(x2-x)+(y2-y)*(y2-y)>mid*mid) left=mid;
        else right=mid;
    }
    Status a;
    a.x=x2;a.y=y2;a.time=time+mid;a.isCal=true;
    return a;

}


void Dp(int state,int num){
    if(f[state][num].isCal==true) return ;
    
    if(state==0){f[state][num]=calcuateTimeAndXY(0,0,0,num);return ;}
    
    double minTime=1e100;
    for(int i=0;i<n;++i)
    if((state&(1<<i))!=0)
    {
        Dp(state^(1<<i),i);
        
        Status tt=calcuateTimeAndXY(f[state^(1<<i)][i].x,f[state^(1<<i)][i].y,f[state^(1<<i)][i].time,num);
        if(tt.time<minTime)
        {
            minTime=tt.time;
            f[state][num]=tt;
        }
    }
    return ;
}

int main()
{
    scanf("%d",&t);
    
    while(t>0)
    {
        t--;
        scanf("%d",&n);
        for(int i=0;i<n;++i)
        scanf("%lf %lf %lf %lf",&p[i].x,&p[i].y,&p[i].r,&p[i].u);
        for(int i=0;i< 1<<n ;++i)
        for(int j=0;j<n;++j)
        f[i][j].isCal=false;
        
        double ans=1e100;
        for(int i=0;i<n;++i)
        {
            Dp(((1<<n) -1)^(1<<i),i);
            
            if(f[((1<<n) -1)^(1<<i)][i].time<ans)
            ans=f[((1<<n) -1)^(1<<i)][i].time;
        
        }
    //    cout<<f[0][0].time<<"   "<<f[0][1].time<<endl;
        printf("%.6f\n",ans);
        
    
    
    }




}

 

 
 
 

转载于:https://www.cnblogs.com/noip/p/9550358.html

hustoj.iso 是一个软件系统镜像文件。Hustoj是一个开源的在线评测系统,它被广泛应用于大学和高中的程序设计教学中。该系统的目标是提供一个方便使用的在线评测和训练环境,使学生能够提交他们的程序代码,并获得即时的评测结果。 hustoj.iso 是Hustoj的系统镜像文件,可以用来部署Hustoj系统。通过将hustoj.iso 文件安装到服务器上,就可以建立一个运行Hustoj系统的评测服务器。用户可以通过web界面访问该服务器,并提交自己的程序代码进行评测。 hustoj.iso 是一个基于Ubuntu操作系统的镜像文件。它集成了所有Hustoj系统所需要的软件和依赖项,并进行了预配置,使得安装和部署变得更加简单。用户只需要将hustoj.iso文件写入到U盘或光盘中,然后引导服务器从U盘或光盘启动,就可以开始安装Hustoj系统了。 使用hustoj.iso 部署Hustoj系统,可以为学生提供一个良好的在线评测环境,帮助他们进行程序设计的学习和训练。学生可以在该系统中提交自己的程序代码,并获得详尽的评测结果,包括运行时间、内存消耗、错误信息等等。同时,Hustoj还具有包括代码分享、竞赛组织等其他功能,能够满足不同需求的学生。 总之,hustoj.iso 是一个用于部署Hustoj系统的镜像文件,通过安装hustoj.iso,可以搭建一个功能完善、易用的在线评测环境,为程序设计学习提供有力的支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值