ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1392. Dreaming of Stars

Why WA#54????
Posted by <-UnderFelixAbove-> 4 Sep 2007 00:21
Hi,Gues!

Please Help me! I have WA#54 and I don't understand what's wrong.

This is my code

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

struct sphere
{
    int x;
    int y;
    int z;
    int r;
    int num;
    bool met;
    sphere(){}
    sphere(int X,int Y,int Z,int R,int Num)
    {
        x = X;
        y = Y;
        z = Z;
        r = R;
        num = Num;
        met = false;

    }
} mas[1005];
int x,y,z,r;
int n;
string STR[1005];
int countSTR;
void input()
{
    cin>>n;
    for (int i=0;i<n;i++)
    {
        cin>>x>>y>>z>>r;
        mas[i] = sphere(x,y,z,r,i);
    }
}
int posR;
int posW;
sphere Q[1005];
void Add(sphere sp)
{
    Q[posW++] = sp;
}
void zero()
{
    posR = 0;
    posW = 0;
    memset(Q,0,sizeof(Q));
}

bool isInter(sphere &a,sphere &b)
{
    int len = (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z);
    int R = (a.r + b.r)*(a.r + b.r);
    if (len>=R)
        return false;
    return true;
}
void search(sphere sp)
{
    zero();
    sp.met = true;
    Add(sp);



    while(posR<posW)
    {
        sphere cur = Q[posR++];
        for (int i=0;i<n;i++)
        {
            if (mas[i].met == false)
                if (isInter(cur,mas[i]))
                {
                    mas[i].met = true;
                    Add(mas[i]);
                }
        }

    }
    int INT[1005];
    int countINT = 0;
    memset(INT,0,sizeof(INT));
    for (int i=0;i<posW;i++)
    {
        INT[countINT++] = Q[i].num;
    }
    sort(INT,INT+countINT);
    string str = "";
    char tmp[10];
    sprintf(tmp,"%i",INT[0]);
    str += tmp;
    for (int i=1;i<countINT;i++)
    {
        sprintf(tmp,"%i",INT[i]);
        str += ", ";
        str += tmp;
    }
    STR[countSTR++] = str;



}
void solve()
{
    for (int i=0;i<n;i++)
    {
        if (mas[i].met==false)
        {
            mas[i].met = true;
            search(mas[i]);
        }
    }
    sort(STR,STR + countSTR);
    for (int i=0;i<countSTR;i++)
    {
        cout<<STR[i]<<endl;
    }
}
int main()
{
    input();
    solve();
    return 0;
}