I've tried my programme on many cases and it finishes his work properly at my comp's. Just sending this code to Uva i get 'Runtime error'.
Please, check my code and tell what can be wrong, coz i'm just sick and tired of getting 'WA' or 'runtime error' sending almost every problem here -_- .
- Code: Select all
#include<iostream>
#include<vector>
#include<set>
#include<cmath>
#include<algorithm>
#include<iomanip>
#define rep(x,n) for (int x = 0; x < n; x++)
#define pb push_back
using namespace std;
struct tr
{
int x,y,z;
void m(int ex, int ey, int ez)
{
x = ex; y = ey; z = ez;
}
};
struct cmp
{
bool operator() (tr a, tr b)
{
if (a.x == b.x)
{
if (a.y == b.y)
{
if (a.z == b.z) return true; else return (a.z < b.z);
}
else return (a.y < b.y);
} else return (a.x < b.x);
}
};
set <tr,cmp> D;
int main()
{ int x,y,z;
vector <int> zaj; zaj.resize(10,0);
do
{
cin >> x >> y >> z;
tr a; a.m(x,y,z); D.insert(a);
} while (! (x == 0 && y == 0 && z == 0));
D.erase(D.begin());
for (set<tr,cmp>::iterator it = D.begin(); it != D.end(); it++)
{
double d1 = -1,d2 = -1; tr d; tr b = *(it);
// cout <<"------------------ " <<b.x << " " << b.y << " " <<b.z << "\n";
if (it != D.begin())
{
--it; d = *(it); ++it;
d1 = sqrt((b.x-d.x)*(b.x-d.x) + (b.y-d.y)*(b.y-d.y) + (b.z-d.z)*(b.z-d.z));
// cout << "D1" <<d1 << "\n";
}
set<tr,cmp>::iterator itk = D.end(); itk--;
if (it != itk)
{
++it; d = *(it); --it;
d2 = sqrt((b.x-d.x)*(b.x-d.x) + (b.y-d.y)*(b.y-d.y) + (b.z-d.z)*(b.z-d.z));
// cout << "d2 " << d2 << "\n";
}
if (d1 != -1 && d2 != -1)
{
//cout << "czc " << int(d1) << " " << int(d2) << "\n";
int g = min(int(d1),int(d2)); if (g < 10)++zaj[g];
// cout << "better " << "\n";
}
else if (d1 == -1 && d2 < 10) { ++zaj[int(d2)]; } else if (d1 < 10) {++zaj[int(d1)]; }
//cout <<"d1 " << d1 << "\n";
//cout << "d2 " << d2 << "\n";
}
rep(x,10)
{
cout << setw(4) << zaj[x] << " ";
}
cout << "\n";
zaj.clear();
D.clear();
return 0;
}
