Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

c++细节问题,求住大神, 问题在标注里面

Posted by root123 at 2012-09-07 13:29:05 on Problem 1755
#include<cmath>
#include<cstring>
#include<vector>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
#define eps 1e-8
#define inf 1<<29
struct point
{
	double x, y;
	bool mark;
	point(){}
	point(double xx, double yy): x(xx), y(yy), mark(1){}
};

double aa[105], bb[105], cc[105];
int n;
vector<point> p;

point intersect(point p1, point p2, double &a, double &b, double &c)
{
	double u = fabs( a * p1.x + b * p1.y + c);
	double v = fabs( a * p2.x + b * p2.y + c);
	point ret;
	ret.x = ( v * p1.x + u * p2.x ) / (u + v);
	ret.y = ( v * p1.y + u * p2.y ) / (u + v);
	return ret;
}

void update(double a, double b, double c)
{
	int i;
	point tp; ///////////////////////////为什么tp定义在里面就WA,定义在外面就AC (C++)
	for(i = 0; i < p.size(); i++)
		if( a * p[i].x + b * p[i].y + c > eps )
			p[i].mark = 1;
		else p[i].mark = 0;
	p.push_back( p[0] );
    for(i = 0; i < p.size() - 1; i++)
	    if( p[i].mark^p[i+1].mark == 1)
		{   // point tp 写在里面就WA, 这是为什么???????????大神帮帮忙  (C++)
			tp = intersect(p[i], p[i+1], a, b, c);///////////////////////////为什么定义在里面就WA,定义在外面就AC  (C++)
			p.insert(p.begin()+i+1, tp);
			i++;
		}
	p.pop_back();
	for(i = 0; i < p.size(); i++)
		if(p[i].mark == 0)
			p.erase(p.begin()+i), i--;
}

 bool solve(int v)
{
	int i;
	for(i = 1; i <= n; i++)
		if(i != v)
		{
			update(1/aa[i] - 1/aa[v], 1/bb[i] - 1/bb[v], 1/cc[i] - 1/cc[v]);
			if(p.size() == 0) return 0;
		}
	return 1;
}

int main()
{
	int i;
    scanf("%d", &n);
	for(i = 1; i <= n; i++)
		scanf("%lf%lf%lf", &aa[i], &bb[i], &cc[i]);
	for(i = 1; i <= n; i++)
	{
		p.clear();
	    p.push_back( point( inf, inf) );
	    p.push_back( point( inf,  0) );
	    p.push_back( point( 0, 0) );
	    p.push_back( point( 0, inf) );
		if(solve(i)) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}



Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator