QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#857438#8864. Ball PassingHeyJinhwi#AC ✓1ms3968kbC++142.0kb2025-01-15 18:04:572025-01-15 18:04:58

Judging History

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

  • [2025-01-15 18:04:58]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3968kb
  • [2025-01-15 18:04:57]
  • 提交

answer

#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
char ss[101];
double x[101],y[101];
struct str{
    double x,y;
    double deg;
    int tkqnsaus;
    char gen;
}st[101];
double xx,yy;
bool s(str a,str b)
{
    if(a.tkqnsaus==b.tkqnsaus)
    {
        return a.deg<b.deg;
    }
    return a.tkqnsaus<b.tkqnsaus;
}
double sq(double x)
{
    return x*x;
}
double dist(int i,int j)
{
    return sqrt(sq(st[i].x-st[j].x)+sq(st[i].y-st[j].y));
}
main()
{
    int n;cin>>n>>ss;
    for(int i=0;i<n;i++)
    {
        cin>>x[i]>>y[i];
        xx+=x[i],yy+=y[i];
        st[i].x=x[i];
        st[i].y=y[i];
        st[i].gen=ss[i];
    }
    xx/=(double)n;
    yy/=(double)n;
    for(int i=0;i<n;i++)
    {
        if(st[i].x==xx)
        {
            st[i].deg=999999;
        }
        else
        {
            st[i].deg=(st[i].y-yy)/(st[i].x-xx);
        }
        if(st[i].x>=xx&&st[i].y>yy)st[i].tkqnsaus=1;
        if(st[i].x<xx&&st[i].y>=yy)st[i].tkqnsaus=2;
        if(st[i].x<=xx&&st[i].y<yy)st[i].tkqnsaus=3;
        if(st[i].x>xx&&st[i].y<=yy)st[i].tkqnsaus=4;
    }
    sort(st,st+n,s);
    double ans=0;
    int b=0,g=0;
    for(int i=0;i<n;i++)
    {
        if(st[i].gen=='B')b++;else g++;
    }
    int i=0,cnt=0;
    if(b)
    {
        for(;;i++)
        {
            if(st[i].gen=='B')cnt++;
            if(cnt==b/2+1)break;
        }
        int j=0;
        for(int k=0;k<b/2;k++)
        {
            while(st[j].gen!='B')j++;
            while(st[i].gen!='B')i++;
            ans+=dist(i,j);
            i++;
            j++;
        }
    }
    cnt=0;
    if(g)
    {
        for(i=0;;i++)
        {
            if(st[i].gen=='G')cnt++;
            if(cnt==g/2+1)break;
        }
        int j=0;
        for(int k=0;k<g/2;k++)
        {
            while(st[j].gen!='G')j++;
            while(st[i].gen!='G')i++;
            ans+=dist(i,j);
            i++;
            j++;
        }
    }
    printf("%.9lf",ans);
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3968kb

input:

4
BBGG
-1 -10
-10 -2
-8 7
7 -8

output:

33.254798014

result:

ok found '33.2547980', expected '33.2547980', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

10
GBGBBBGBBG
-30 2
-28 10
-5 30
6 29
15 26
22 20
29 9
27 -12
-14 -27
-22 -20

output:

269.695383045

result:

ok found '269.6953830', expected '269.6953830', error '0.0000000'

Test #3:

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

input:

18
GBBBBGBGBGBBGGGGBB
-1820 -414
-1992 -92
-77 999
75 999
422 978
471 972
871 900
1343 741
1790 -446
556 -961
148 -997
28 -1000
23 -1000
-493 -969
-816 -913
-1002 -865
-1432 -698
-1671 -550

output:

21614.281391566

result:

ok found '21614.2813916', expected '21614.2813916', error '0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

40
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
9506 -2484
9872 -1278
9980 -501
9992 -323
7528 5266
7447 5339
7074 5655
5984 6410
5834 6498
5537 6662
5459 6703
3250 7566
2640 7716
896 7968
637 7984
-1592 7898
-1863 7860
-2419 7762
-3277 7558
-3941 7353
-7798 5008
-9393 2745
-9617 2192
-9752 1772
-9882 -...

output:

351971.753259776

result:

ok found '351971.7532598', expected '351971.7532598', error '0.0000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

50
BBBGBGGGGGBGGGGGGGGBBGGGGBBBBBBGGGBGGBGBGGBBGBGBGG
1420 -4949
4182 -4542
4684 -4418
5875 -4046
6094 -3964
7896 -3068
8588 -2561
8764 -2408
8929 -2251
9377 -1737
9724 -1166
8443 2679
8109 2926
7842 3103
4660 4424
4561 4450
3837 4617
3542 4676
3281 4723
3208 4736
3008 4768
1136 4968
131 5000
-1002 ...

output:

331254.024145006

result:

ok found '331254.0241450', expected '331254.0241450', error '0.0000000'