- UID
- 675164
- 积分
- 224
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2013-4-19
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- #include <stdio.h>
- #include <math.h>
- struct point {
- float x;
- float y;
- } ptfirst, pt1, pt2, pt0={0, 0};
- float triangsize(struct point pt0, struct point pt1, struct point pt2);
- int main(void)
- {
- int n;
- while (scanf("%d", &n) && n>=3) {
- float sum=0, amount, length;
- scanf("%f %f", &pt1.x, &pt1.y);
- scanf("%f %f", &pt2.x, &pt2.y);
- ptfirst = pt1; // 保存起始点
- sum += triangsize(pt0, pt1, pt2);
- n -= 2; // 已读取2行
- for ( ; n>0; n--) {
- pt1 = pt2;
- scanf("%f %f", &pt2.x, &pt2.y);
- sum += triangsize(pt0, pt1, pt2);
- }
- sum += triangsize(pt0, pt2, ptfirst);
- sum = (float)fabs(sum);
- scanf("%f", &amount);
- length = amount / sum;
- printf("BAR LENGTH: %.2f\n", length);
- }
- return 0;
- }
- float triangsize(struct point pt0, struct point pt1, struct point pt2)
- {
- return ((pt0.x*pt1.y + pt1.x*pt2.y + pt2.x*pt0.y) - (pt2.x*pt1.y + pt1.x*pt0.y + pt0.x*pt2.y)) * 0.5f;
- }
|
|