i am solving spoj.pl/problems/SICRANO/
[color=#FF0000]I think in this question all we need to do is check the slope of point (to be checked) with intial point of segment ,also checking checking whether that point lies between segment or not.. and if slope is same as of SEGMENT>> it lies on segement .[/color]
IS LOGIC CORRECT ???
here is my code in C++ using the same logic ???
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int t,i,n,m,k,count;
scanf("%d",&t);
while(t--)
{
double elev;
count=0;
scanf("%d %d",&n,&m);
int px[n],py[n];
for(i=0;i<n;i++)
scanf("%d %d",&px[i],&py[i]);
int sx1[m],sy1[m],sx2[m],sy2[m];
double slope[m];
for(i=0;i<m;i++)
{
scanf("%d %d %d %d",&sx1[i],&sy1[i],&sx2[i],&sy2[i]);
slope[i]=(((double)sy2[i]-(double)sy1[i])/((double)sx2[i]-(double)sx1[i]));
}
for(k=0;k<m;k++)
{
count=0;
for(i=0;i<n;i++)
{
elev=0.0;
if((sx1[k]<=px[i])&&(px[i]<=sx2[k])&&((sy1[k]<=py[i])&&(py[i]<=sy2[k])))
{
if((sy1[k]==py[i])&&(sx1[k]==px[i]))
count++;
else
{
elev+=(((double)sy1[k]-(double)py[i])/((double)sx1[k]-(double)px[i]));
if(elev==slope[k])
count++;
}
}
}
printf("%d\n",count);
}
}
return 0;
}
checked on many .. even with infinity cases!!! still WA
please help !!!
created
last reply
- 25
replies
- 507
views
- 7
users
- 2
links