CE

Write here if you have problems with your C++ source code

Moderator: Board moderators

CE

Postby kapysh » Wed Jul 19, 2006 10:53 am

Please help me. What compile error has occured in this code:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
int N,i,j,k,l,max;
vector<int> mas[40004];
cin>>N;
while(N!=0)
{
for(i=0;i<40004;i++)
{
mas[i].clear();
mas[i].reserve(100);
}
max=2000000000;
for(i=0;i<N;i++)
{
cin>>j;
cin>>k;
mas[j].insert(mas[j].begin(),k);// .insert(k);
}
// comparing points with same x coordinate value
for(i=0;i<40001;i++)
{
while(mas[i].empty() && i<40002)
i++;
sort(mas[i].begin(),mas[i].end());
if(!mas[i].empty())
for(k=0;k<mas[i].size()-1;k++)
if((mas[i][k+1]-mas[i][k])<max)
max=mas[i][k+1]-mas[i][k];
}
// comparing points with difference x coordinate values
if(max==0)
{
cout.precision(4);
cout<<fixed<<max<<endl;
continue;
}
for(i=0;i<40000;i++)
{
while(mas[i].empty() && i<40001)
i++;
for(j=i+1;j<40001;j++)
{
while(mas[j].empty() && j<40001)
j++;
if((i-j)*(i-j)>=max)
continue;
for(k=0;k<mas[i].size();k++)
for(l=0;l<mas[j].size();l++)
if(((i-j)*(i-j)+(mas[i][k]-mas[j][l])*(mas[i][k]-mas[j][l]))<max)
max=(i-j)*(i-j)+(mas[i][k]-mas[j][l])*(mas[i][k]-mas[j][l]);
}
}
if(max>=100000000)
cout<<"INFINITY"<<endl;
else
{
cout.precision(4);
cout<<fixed<<sqrt((double)max)<<endl;
}
cin>>N;
}
return 0;
}
kapysh
New poster
 
Posts: 5
Joined: Wed Jul 19, 2006 10:13 am

Postby sumankar » Wed Jul 19, 2006 12:40 pm

cout.precision/cout << fixed ... is giving you the CE. Exercise for the reader: find out which one and how to fix it ;) Also, delete the other post.
sumankar
A great helper
 
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta


Return to C++

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest