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 namespace std;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int N = 1225;
int t, n, tn;
struct Point {
	double x, y;
	void read() {
		scanf("%lf%lf", &x, &y);
 	}
} p[N];

double r[2 * N];

double C(int n, int m) {
	if (m > n) return 0;
	double ans = 1;
	for (int i = 0; i < m; i++)
		ans = ans * (n - i) / (i + 1);
	 return ans;
}

double cal(Point a, Point b) {
	return atan2(b.y - a.y, b.x - a.x);
}

double solve(int num) {
	tn = 0;
	double ans = 0;
	for (int i = 0; i < n; i++) {
		if (i == num) continue;
		r[tn++] = cal(p[num], p[i]);
 	}
 	sort(r, r + tn);
	int j = 1;
	for (int i = 0; i < tn; i++)
		r[i + tn] = r[i] + 2 * pi;
  	for (int i = 0; i < tn; i++) {
	  	while (fabs(r[j] - r[i]) - pi < -eps) j++;
  		ans += C(j - i - 1, 2);
	}
	return C(tn, 3) - ans;
}

int main() {
	int cas = 0;
	while (scanf("%d", &n) && n) {
		double ans = 0;
		for (int i = 0; i < n; i++)
			p[i].read();
		for (int i = 0; i < n; i++) {
			ans += solve(i);
  		}
  		printf("City %d: %.2lf\n", ++cas, ans / C(n, 3));
 	}
	return 0;
}


  • 1
    点赞
  • 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、付费专栏及课程。

余额充值