hdu1115

参考链接:

http://www.cnblogs.com/bo-tao/archive/2011/08/16/2141395.html

http://blog.csdn.net/ysc504/article/details/8812339

http://www.cnblogs.com/jbelial/archive/2011/08/08/2131165.html

用第三个链接中的第一种方法,wr了

wr的代码:

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

int main(){
    int t;
    double ansx,ansy;
    double tempx,tempy;
    int n;

    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        ansx=0;
        ansy=0;
        for(int i=1;i<=n;i++){
            scanf("%lf%lf",&tempx,&tempy);
            ansx+=tempx;
            ansy+=tempy;
        }
        printf("%.2lf %.2lf\n",ansx/n,ansy/n);
    }

    return 0;
}

一直wr,后来ac,

参考链接:http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=15250&messageid=1&deep=0

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

double qarea(double x1,double y1,double x2,double y2,double x3,double y3){
    return ((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2;//公式,求面积
}

int main(){
    int t;
    int n;
    double x1,y1,x2,y2,x3,y3;
    double ansx,ansy;
    double allarea;

    scanf("%d",&t);
    while(t--){
        ansx=0;
        ansy=0;
        allarea=0;
        scanf("%d",&n);
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);

        for(int i=1;i<=n-2;i++){
            scanf("%lf%lf",&x3,&y3);
            double tempx=(x1+x2+x3);//把3放下面才ac,否则wr
            double tempy=(y1+y2+y3);
            double area=qarea(x1,y1,x2,y2,x3,y3);
            allarea+=area;
            ansx+=tempx*area;//少写了加号,下同
            ansy+=tempy*area;
            x2=x3;
            y2=y3;
        }

        printf("%.2lf %.2lf\n",ansx/allarea/3,ansy/allarea/3);
    }

    return 0;
}


转载于:https://www.cnblogs.com/ahahah/p/4918188.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值