【洛谷P2785】物理1(physic1) - 磁通量【计算几何,叉积】

在这里插入图片描述
l i n k link link

分析:

先叉积求多边形面积 磁通量 = = = 磁感应强度 × \times × 面积

CODE:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define reg register
using namespace std;
const int N=1e5+5;
int n;
double b,ans; 
struct node{
	double x,y;
}a[N];
double m(node a,node b,node c){return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);}
int main()
{
	scanf("%d%lf",&n,&b);
	for(int i=1;i<=n;i++)
		scanf("%lf%lf",&a[i].x,&a[i].y);
	for(int i=2;i<=n;i++)
		ans+=m(a[i],a[i-1],a[1]);
	ans+=m(a[n],a[1],a[1]);
	printf("%.4lf",fabs(ans*b)*0.5000);
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值