QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#24091#2950. Growing Some OobleckGeorge_Plover#TL 3ms3776kbC++201.6kb2022-03-26 13:20:012022-04-30 04:55:39

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 04:55:39]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:3776kb
  • [2022-03-26 13:20:01]
  • 提交

answer

#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 111
using namespace std;
int n;
struct Circ{
    double x,y,r,s;
};
double dis(Circ A,Circ B)
{
    return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)); 
}
double touch_t(Circ A,Circ B)
{
    return (dis(A,B)-A.r-B.r)/(A.s+B.s);
}
vector <Circ> vec;
void merge(int l)
{
    Circ c;c.x=0;c.y=0;c.r=0;c.s=0;
    Circ me = vec[l];
    int cnt=0;
    for(auto it = vec.begin();it!=vec.end();)
    {
        if(dis(me,*it)-me.r-it->r <= 0)
        {
            cnt++;
            c.r+=(it->r)*(it->r);
            c.s=max(c.s,it->s);
            c.x+=it->x;
            c.y+=it->y;
            it = vec.erase(it);
        }
        else
            ++it;
    }
    c.r=sqrt(c.r);c.x/=cnt;c.y/=cnt;
    vec.push_back(c);
    if(cnt==1)return;
    merge((int)vec.size()-1);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        Circ c;
        cin>>c.x>>c.y>>c.r>>c.s;
        vec.push_back(c);
    }

    while(vec.size()!=1)
    {
        int l=-1,r=-1;
        for(int i=0;i<vec.size();i++)
            for(int j=i+1;j<vec.size();j++)
                if(l==-1 || touch_t(vec[l],vec[r])>touch_t(vec[i],vec[j]))
                {
                    l=i;r=j;
                }
        double t = touch_t(vec[l],vec[r]);
        for(int i=0;i<vec.size();i++)
        {
            vec[i].r += t*vec[i].s;
        }
        merge(l);
    }  

    printf("%.10lf %.10lf\n%.10lf\n",vec[0].x,vec[0].y,vec[0].r);


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3776kb

input:

3
10 10 5 1
24 10 7 1
16 2 2 1

output:

16.5000000000 6.0000000000
10.4403065089

result:

ok 3 numbers

Test #2:

score: 0
Accepted
time: 3ms
memory: 3732kb

input:

5
-5 0 1 1
6 0 1 1
0 7 1 1
0 -8 1 1
0 0 1 2

output:

1.1875000000 -3.1250000000
7.6167768131

result:

ok 3 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 3752kb

input:

2
-1000000000 0 1 1
1000000000 0 1 1

output:

0.0000000000 0.0000000000
1414213562.3730950356

result:

ok 3 numbers

Test #4:

score: 0
Accepted
time: 3ms
memory: 3756kb

input:

4
-100000000 -1000000000 1 2
1000000000 -1000000000 1 2
-1000000000 1000000000 1 3
1000000000 1000000000 1 3

output:

225000000.0000000000 0.0000000000
1673350486.9608104229

result:

ok 3 numbers

Test #5:

score: 0
Accepted
time: 3ms
memory: 3732kb

input:

4
-100000000 -1000000000 1 1000000
1000000000 -1000000000 1 1000000
-1000000000 1000000000 1 3
1000000000 1000000000 1 3

output:

-137500000.0000000000 500000000.0000000000
2074241311.0123999119

result:

ok 3 numbers

Test #6:

score: -100
Time Limit Exceeded

input:

10
-1 1 1 1
3 1 1 1
8 1 1 1
21 1 1 1
55 1 1 1
155 1 1 1
355 1 1 1
900 1 1 1
2000 1 1 1
20000 1 1 1

output:


result: