so water....
/*************************
* Creater:Sevenster *
* Time:2012.07.31 15:14 *
* PID:POJ 2318 *
*************************/
#include<iostream>
#include<stdio.h>
using namespace std;
class CPoint
{
public:
double x, y;
};
class CVector
{
public:
double x, y;
};
/**
CVector CPoint::operator -( CPoint b, CPoint a )
{
return CVector( b.x- a.x, b.y- a.y );
}
double operator ^( CVector p, CVector q )
{
return p.x* q.y- q.x* p.y;
}
*/
double xmult( double x1,double y1,double x2,double y2 )
{
return x1* y2- x2* y1;
}
int main()
{
int n, m;bool flag=0;
double x1, y1, x2, y2;
while( scanf( "%d", &n )!= EOF )
{
if( flag==true )
printf( "\n" );
flag=true;
if( n==0 )
break;
scanf( "%d%lf%lf%lf%lf", &m, &x1, &y1, &x2, &y2 );
CPoint up[5555],down[5555],toys[5555];
int cnt[5555];
memset( cnt,0,sizeof(cnt) );
for( int i=1;i<=n;i++ )
{
up[i].y=y1;
down[i].y=y2;
scanf( "%lf%lf", &up[i].x, &down[i].x );
}
up[0].x= x1; up[0].y= y1;
down[0].x= x1; down[0].y= y2;
up[n+1].x= x2; up[n+1].y= y1;
down[n+1].x= x2; down[n+1].y= y2;
for( int i=0;i<m;i++ )
scanf( "%lf%lf", &toys[i].x, &toys[i].y );
for( int i=0;i<m;i++ )
for( int j=1;j<=n+1;j++ )
{
if( xmult(toys[i].x- down[j].x, toys[i].y- down[j].y, up[j].x- down[j].x, up[j].y- down[j].y )< 0 )
//if( (toys[i]- down[j])^ (up[j]- down[j]) )
{
cnt[j-1]++;
break;
}
}
for( int i=0;i<=n;i++ )
{
printf( "%d: %d\n", i, cnt[i] );
}
}
return 0;
}
本文详细介绍了如何使用C++实现矢量和点之间的运算,包括矢量减法和叉乘,并通过实例展示了如何计算矢量的点乘。

2225

被折叠的 条评论
为什么被折叠?



