P1035永远60分求解

P1035 [NOIP2002 普及组] 级数求和

jadekwok @ 2019-11-14 16:48:03

#include <stdio.h>

int main()
{
    int k,n=1;
    float Sn=0;
    scanf("%d",&k);
    while(k)
    {
        Sn+=1.0/n;
        if(Sn>k)
            break;
        n++;
    }
    printf("%d",n);
    return 0;
}

已经尝试给所有带Sn处旁边的数值乘1.0 但也不可以 大神求解


by 林聪 @ 2019-11-15 00:04:03

@yinlei 不用了,我马上退役了


by yinlei @ 2019-11-15 00:15:55

@林聪 再帮我看一道题吧 找好久都没找出来


by 林聪 @ 2019-11-15 00:16:47

@yinlei 额,哪道


by yinlei @ 2019-11-15 00:22:28

@林聪

include<stdio.h>

int main() { int num,num1,num2,num3,p1,p2,p3,p,a1,a2,a3; scanf("%d",&num); scanf("%d%d",&num1,&p1); scanf("%d%d",&num2,&p2); scanf("%d%d",&num3,&p3); { if(num%num1==0) a1=(num/num1)p1; else a1=(num/num1+1)p1; } { if(num%num2==0) a2=(num/num2)p2; else a2=(num/num2+1)p2; } {if(num%num3==0) a3=(num/num3)p3; else a3=(num/num3+1)p3; } if(a1<a2&&a1<a3) p=a1; if(a2<a3&&a2<a1) p=a2; if(a3<a2&&a3<a1); p=a3;
printf("%d\n",p); return 0; }


9998
128 233
128 2333
128 666 的时候一直不对输出sum3的值

by 林聪 @ 2019-11-15 00:23:58

@yinlei 这啥啊,用markdown好么,回复讨论第一排的“插入代码”


by yinlei @ 2019-11-15 00:26:07

#include<stdio.h>
int main()
{
    int num,num1,num2,num3,p1,p2,p3,p,a1,a2,a3;
    scanf("%d",&num);
    scanf("%d%d",&num1,&p1);
    scanf("%d%d",&num2,&p2);
    scanf("%d%d",&num3,&p3);
    {   if(num%num1==0)
        a1=(num/num1)*p1;
    else
        a1=(num/num1+1)*p1;
    }
    {   if(num%num2==0)
        a2=(num/num2)*p2;
    else
        a2=(num/num2+1)*p2;
    }
    {if(num%num3==0)
        a3=(num/num3)*p3;
    else
        a3=(num/num3+1)*p3;
    }
    if(a1<a2&&a1<a3)
        p=a1;
            if(a2<a3&&a2<a1)
                    p=a2;
                if(a3<a2&&a3<a1);
                    p=a3;       
                printf("%d\n",p);
    return 0;
}

by yinlei @ 2019-11-15 00:27:43

@林聪 9998 128 233 128 2333 128 666的时候一直输出sum3是为什么啊? 是不是精度的问题?


by 林聪 @ 2019-11-15 00:28:57

@yinlei 这是哪道题


by yinlei @ 2019-11-15 00:30:07

@林聪P1909


上一页 |