当前位置: 首页>>代码示例>>C++>>正文


C++ Convex::size方法代码示例

本文整理汇总了C++中Convex::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Convex::size方法的具体用法?C++ Convex::size怎么用?C++ Convex::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Convex的用法示例。


在下文中一共展示了Convex::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: convexIntersection

Convex convexIntersection(Convex v1, Convex v2) {
    vector<Halfplane> h;
    for (int i = 0; i < v1.size(); i++) {
        h.push_back(Halfplane(v1[i], v1[(i+1) % v1.size()]));
    }
    for (int i = 0; i < v2.size(); i++) {
        h.push_back(Halfplane(v2[i], v2[(i+1) % v2.size()]));
    }
    return halfplaneIntersection(h);
}
开发者ID:wujysh,项目名称:2015_ACM_Summer_Training,代码行数:10,代码来源:ZOJ_3154_Mixed_Juice.cpp

示例2: area

double area(Convex a) {
    double sum = 0;
    a.push_back(a[0]);
    for (int i = 0; i < a.size() - 1; i++) {
        sum += cross(a[i], a[i+1]);
    }
    return sum / 2.0;
}
开发者ID:wujysh,项目名称:2015_ACM_Summer_Training,代码行数:8,代码来源:ZOJ_3154_Mixed_Juice.cpp

示例3: convex_hull

Convex convex_hull(Convex a) {
    Convex res(2 * a.size() + 5);
    sort(a.begin(), a.end(), comp_less);
    a.erase(unique(a.begin(), a.end()), a.end());
    int m = 0;
    for (int i = 0; i < a.size(); i++) {
        while (m > 1 && sgn(cross(res[m-1]-res[m-2], a[i]-res[m-2])) <= 0) {
            m--;
        }
        res[m++] = a[i];
    }
    int k = m;
    for (int i = a.size() - 2; i >= 0; i--) {
        while (m > k && sgn(cross(res[m-1]-res[m-2], a[i]-res[m-2])) <= 0) {
            m--;
        }
        res[m++] = a[i];
    }
    res.resize(m);
    if (a.size() > 1) {
        res.resize(m-1);
    }
    return res;
}
开发者ID:wujysh,项目名称:2015_ACM_Summer_Training,代码行数:24,代码来源:ZOJ_3154_Mixed_Juice.cpp

示例4: main

int main(int argc, char const *argv[])
{
	Convex v1, v2;
	v1.push_back(Point(0,0));
	v1.push_back(Point(1,1));
	v1.push_back(Point(0,2));
	v1.push_back(Point(-1,1));
	v1.push_back(Point(-0.5,0));

	v2.push_back(Point(1,0));
	v2.push_back(Point(2,1));
	v2.push_back(Point(1,2));
	v2.push_back(Point(0,1));
	v2.push_back(Point(0.5,0));

	Convex v = convexIntersection(v1, v2);
	for (int i = 0; i < v.size(); ++i)
	{
		cout << v[i] << endl;
	}
	return 0;
}
开发者ID:JS00000,项目名称:acmCode,代码行数:22,代码来源:3_1_11.cpp

示例5: convexIntersection

Convex convexIntersection(Convex v1, Convex v2)
{
	vector<Halfplane> h, h1, h2;
	for (int i = 0; i < v1.size(); ++i)
		h1.push_back(Halfplane(v1[i], v1[(i+1)%v1.size()]));
	for (int i = 0; i < v2.size(); ++i)
		h2.push_back(Halfplane(v2[i], v2[(i+1)%v2.size()]));
	int p1 = 0, p2 = 0;
	while(p1 < h1.size() && p2 < h2.size())
	{
		int res = sgn(arg(h1[p1].second - h1[p1].first) - arg(h2[p2].second - h2[p2].first));
		if (res < 0)
			h.push_back(h1[p1++]);
		else if (res > 0)
			h.push_back(h2[p2++]);
		else
			if (sgn(cross(h1[p1].first - h2[p2].first, h2[p2].second - h2[p2].first)) < 0)
			{
				h.push_back(h1[p1++]);
				p2++;
			}
			else
			{
				h.push_back(h2[p2++]);
				p1++;
			}
	}
	while(p1 < h1.size()) 
		h.push_back(h1[p1++]);
	while(p2 < h2.size()) 
		h.push_back(h2[p2++]);

	deque<Halfplane> q;
	deque<Point> ans;
	q.push_back(h[0]);
	for (int i = 1; i < int(h.size()); ++i)
	{
		if (sgn(arg(h[i].second - h[i].first) - arg(h[i-1].second - h[i-1].first)) == 0)
			continue;
		while (ans.size() > 0 && !satisfy(ans.back(), h[i]))
		{
			ans.pop_back();
			q.pop_back();
		}
		while (ans.size() > 0 && !satisfy(ans.front(), h[i]))
		{
			ans.pop_front();
			q.pop_front();
		}
		ans.push_back(crosspoint(q.back(), h[i]));
		q.push_back(h[i]);
	}
	while (ans.size() > 0 && !satisfy(ans.back(), q.front()))
	{
		ans.pop_back();
		q.pop_back();
	}
	while (ans.size() > 0 && !satisfy(ans.front(), q.back()))
	{
		ans.pop_front();
		q.pop_front();
	}
	ans.push_back(crosspoint(q.back(), q.front()));
	return vector<Point>(ans.begin(), ans.end());
}
开发者ID:JS00000,项目名称:acmCode,代码行数:65,代码来源:3_1_11.cpp


注:本文中的Convex::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。