TOJ1100

http://acm.tju.edu.cn/toj/showp1100.html

个人问题在于:对题中

Answers must be rounded to six digits after the decimal point.

这句话的要求理解不到位,测试了几个结果都是正确的,但是总是WA,后来上网参考其他代码才发现是自己在输出时对格式的要求不到位。

else printf("%.6f\n", sqrt((total*6.0)/no));

以上应该是正确的输出语句,对输出格式(小数点后保留6位)做了要求。

代码:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int num[50];

int GCD(int a, int b){
    if(a>b) return GCD(a-b,b);
    if(a<b) return GCD(a,b-a);
    else return a;
}

int main(){
    int N;
    int yes, no, total;
    while(scanf("%d", &N) && N != 0){
        yes = 0;
        no = 0;
        total = 0;
        for(int i = 0; i < N; i++){
            scanf("%d", &num[i]);
        }
        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                int judge = GCD(num[i], num[j]);
                if(judge == 1) no++;
                else yes++;
                total++;
            }
        }
        //printf("%d %d %d %f", total, yes, no, (total*6)/no);
        if(total == yes) printf("No estimate for this data set.\n");
        else printf("%.6f\n", sqrt((total*6.0)/no));
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值