hdu 3629 Convex(计数问题)

题目链接:hdu 3269 Convex

题目大意:给出n个点,问任选四个点可以组成多少个凸四边形。

解题思路:和uav11529的做法是一样的,只不过求的东西不一样。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;
const int N = 1205;
const double pi = 4 * atan(1.0);
const double eps = 1e-9;

int n;
ll s;
double r[2*N];
struct point {
    double x, y;
}p[N];

ll Count (int d) {
    int c = 0, mv = 0;
    for (int i = 0; i < n; i++) {
        if (i == d)
            continue;

        double a = atan2(p[i].y-p[d].y, p[i].x-p[d].x);
        r[c] = a;
        r[c+n-1] = a + 2*pi;
        c++;
    }

    c = 2 * n - 2;
    sort(r, r + c);

    ll ans = 0;

    for (int i = 0; i < n-1; i++) {
        double tmp = r[i] + pi;

        while (tmp > r[mv])
            mv++;
        ll cnt = mv - i - 1;
        ans = ans + cnt * (cnt-1) / 2;
    }
    return s - ans;
}

ll solve () {
    s = (n-1) * (n-2) * (n-3) / 6;
    ll c = s * n / 4;
    ll ans = 0;

    for (int i = 0; i < n; i++)
        ans += Count(i);

    return c - ans;
}

int main () {
    int cas;
    cin >> cas;
    while (cas--) {
        cin >> n;
        for (int i = 0; i < n; i++)
            cin >> p[i].x >> p[i].y;
        cout << solve() << endl;
    }
    return 0;
}

hdu 3629 Convex(计数问题)

时间: 2024-10-09 21:39:44

hdu 3629 Convex(计数问题)的相关文章

hdu 3629 Convex

题意:给你N个点,让你选四个点组成凸多边形,求总的方法数 详细解释:http://blog.sina.com.cn/s/blog_64675f540100ksug.html 1 #include<iostream> 2 #include<vector> 3 #include<cstring> 4 #include<cstdio> 5 #include<cmath> 6 #include<stdlib.h> 7 #include<

HDU 4832(DP+计数问题)

HDU 4832 Chess 思路:把行列的情况分别dp求出来,然后枚举行用几行,竖用几行,然后相乘累加起来就是答案 代码: #include <stdio.h> #include <string.h> #include <iostream> using namespace std; typedef long long ll; const ll MOD = 9999991; const int N = 1005; int t, n, m, k, x, y; ll dp1

hdu 5979 Convex

Convex Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 670    Accepted Submission(s): 438 Problem Description We have a special convex that all points have the same distance to origin point.As y

UVA 11529 - Strange Tax Calculation(计数问题)

题目链接:11529 - Strange Tax Calculation 题意:平面上n个建筑物,3个建筑物可以组成一个三角形,计算平均每个三角形内有多少个点 思路:问题等价于,求凹四边形的占所有四边形的比例,用O(n^2)的算法,跟 HDU 3629 Convex 这题是一个道理 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> using n

【转】[专题学习][计算几何]

原文地址:http://www.cnblogs.com/ch3656468/archive/2011/03/02/1969303.html 基本的叉积.点积和凸包等东西就不多说什么了,网上一搜一大堆,切一些题目基本熟悉了就差不多了. 一些基本的题目可以自己搜索,比如这个blog:http://blog.sina.com.cn/s/blog_49c5866c0100f3om.html 接下来,研究了半平面交,思想方法看07年朱泽园的国家队论文,模板代码参考自我校大牛韬哥: http://www.o

UVA - 11529 Strange Tax Calculation

The people living in large citieshave to pay more tax than people living in rural areas. That is because incities people have many facilities, which rural people don't have. Also peoplein large and famous cities tend to pay more tax than people livin

hdu 2841 Visible Trees(计数问题)

题目链接:hdu 2841 Visible Trees 题目大意:一个n?m的矩阵,每个整数点上有树,人站在(0,0)点,问可以看见多少棵树. 解题思路:和uva1393是一道相同类型的题目,只不过这道题目的n比较大,不能预处理.必须用另外一种方法. 将矩阵按照(0,0)和(n,m)两天连成的直线分成两部分,分别计算,但是(n,m)这条线被计算了两次,于是减掉1. dp[i]表示这一列上有多少个点是可以被看见的,因为矩阵被对半分了,所以点的个数为m?in,同时还要计算每次看见的点会把后面的给挡住

hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少?如果不存在,输出0: 思路: 有解的几种条件: 1. mn , mx 变化单调: 2. mn,mx 不能同时变化: 3. 一个位置可选的个数>0; 当解存在时,递推出每次可选择的个数,num += mx[i] - mx[i-1] + mn[i-1] - mn[i] - 1; 即可: 坑:开始想成了

Hdu 3662 3D Convex Hull(三维凸包)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3662 思路:三维凸包模板. #include<cstdio> #include<vector> #include<cstring> #include<iostream> #include<algorithm> #define PR 1e-8 #define N 510 using namespace std; struct TPoint { doub