152 - Runtime error

All about problems in Volume I. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

152 - Runtime error

Postby mic122 » Mon Apr 09, 2012 1:07 pm

Hi guys !

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;
}
mic122
New poster
 
Posts: 6
Joined: Mon Apr 09, 2012 1:01 pm

Re: 152 - Runtime error

Postby brianfry713 » Mon Apr 09, 2012 9:59 pm

Input:
1 1 1
255 255 255
0 0 0

AC output:
Code: Select all
   0   0   0   0   0   0   0   0   0   0
brianfry713
Guru
 
Posts: 1864
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 152 - Runtime error

Postby mic122 » Mon Apr 09, 2012 10:28 pm

For this in my output is the same
mic122
New poster
 
Posts: 6
Joined: Mon Apr 09, 2012 1:01 pm

Re: 152 - Runtime error

Postby brianfry713 » Mon Apr 09, 2012 10:32 pm

Yes but you produce a RE.
brianfry713
Guru
 
Posts: 1864
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 152 - Runtime error

Postby mic122 » Mon Apr 09, 2012 10:34 pm

Once I had RE but now all runs ok here...

Aaargh... For the following input :

Code: Select all
10 10 0
10 10 0
255 255 255
1 1 1
0 0 0


It wrote :

Code: Select all
 2 0 0 0 0 0 0 0 0 0
(ofc with the spaces)
mic122
New poster
 
Posts: 6
Joined: Mon Apr 09, 2012 1:01 pm

Re: 152 - Runtime error

Postby brianfry713 » Wed Apr 11, 2012 2:04 am

For input:
Code: Select all
10 10 0
10 10 0
255 255 255
1 1 1
0 0 0


AC Output:
Code: Select all
   2   0   0   0   0   0   0   0   0   0
brianfry713
Guru
 
Posts: 1864
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to Volume I

Who is online

Users browsing this forum: No registered users and 1 guest