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

题目链接:uva 11529 - Strange Tax Calculation

题目大意:给出若干个点,保证随意三点不共线。随意选三个点作为三角行,其它点若又在该三角形内,则算是该三角形内部的点。问全部情况的三角形平均每一个三角形有多少个内部点。

解题思路:三角形的总数非常easy求C(3n),如今就是要求各个三角形内部点的总数。相同我们能够反过来,求每一个点在多少个三角形的内部。
然后我们确定一个点,求该点在多少个三角的内部。剩余n-1个点。能够组成C(3n1])个三角形,所以仅仅要求出该点在哪些三角形的外部就可以。

红色点为选中的点,将周围点依照与选中点的极角进行排序,每次枚举一点,它的极角为a。全部极角小于a+pi的点。这些点组成的三角形。选中点一定在外部。处理一周的方式是将点的数组扩大两倍,将全部点的极角加上pi有保留在延长的数组中。

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

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

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

double 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);

    double ans = 0;

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

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

double solve () {
    s = (n-1) * (n-2) * (n-3) / 6.0;
    double c = n * (n-1) * (n-2) / 6.0;
    double ans = 0;

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

    return ans / c;
}

int main () {
    int cas = 1;
    while (scanf("%d", &n) == 1 && n) {
        for (int i = 0; i < n; i++)
            scanf("%lf%lf", &p[i].x, &p[i].y);
        printf("City %d: %.2lf\n", cas++, solve());
    }
    return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The Cortex-M0 processor does not have a hardware divider, which means that division calculations are performed using software routines. There are various algorithms for performing software division, but one commonly used method is called "long division". In long division, the divisor is repeatedly subtracted from the dividend until the remainder is less than the divisor. The number of times the divisor is subtracted is the quotient, and the remainder is the final result. This process is repeated until all digits of the dividend have been processed. Here is a sample code for performing integer division on Cortex-M0 using long division: ``` int divide(int dividend, int divisor) { int quotient = 0, remainder = 0; int sign = ((dividend < 0) ^ (divisor < 0)) ? -1 : 1; // convert both operands to positive if (dividend < 0) dividend = -dividend; if (divisor < 0) divisor = -divisor; // perform long division for (int i = 31; i >= 0; i--) { remainder <<= 1; // left shift remainder remainder |= (dividend >> i) & 1; // add next bit from dividend to remainder if (remainder >= divisor) { remainder -= divisor; quotient |= (1 << i); // set corresponding bit in quotient } } // apply sign quotient = sign * quotient; return quotient; } ``` Note that this code assumes that both the dividend and divisor are 32-bit integers. It also handles negative operands correctly and applies the correct sign to the result. However, it may not be the most efficient implementation and may need to be optimized for specific use cases.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值