题解

215 条题解

  • 3
    @ 2017-05-07 22:19:01
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    
    char rd;    int pn;
    template<typename Type>
    inline void read(Type& v)
    {
        pn=1;
        while((rd=getchar())<'0'||rd>'9')
            if(rd=='-')
                pn=-1;
        v=rd-'0';
        while((rd=getchar())>='0'&&rd<='9')
            v=v*10+rd-'0';
        v*=pn;
    }
    template<typename Type>
    inline void out(Type v,bool c=1)
    {
        if(v==0)
            putchar(48);
        else  
        {
            if(v<0)
            {
                putchar('-');
                v=-v;
            }
            int len=0,dg[20];  
            while(v>0)
            {
                dg[++len]=v%10;
                v/=10;
            }  
            for(int i=len;i>=1;i--)
                putchar(dg[i]+48);  
        }
        if(c)
            putchar('\n');
        else
            putchar(' ');
    }
    
    double p, q;
    
    int main()
    {   
        scanf("%lf%lf", &p, &q);
        p/=100; q/=100;
        for(int i = 0;;i++)
            if(int(q*i-0.000001)-int(p*i+0.000001)>=1)
            {  
                printf("%d\n", i);
                return 0;
            }
        return 0;
    }
    
  • 1
    @ 2021-03-16 09:49:47
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <deque>
    using namespace std;
    
    namespace dts
    {
        int ans;
        double p,q;
        
        void main()
        {
            scanf("%lf%lf",&p,&q);
            p/=100,q/=100;
            for (int i=1,flag=0;!flag;i++)
            {
                int l,r;
                for (l=0,r=i;r-l>1;)
                {
                    int mid=(l+r)>>1;
                    double rate=double(mid)/double(i);
                    if (rate<=p)
                        l=mid;
                    else
                        r=mid;
                }
                double rate=double(l)/double(i);
                if (p<rate&&rate<q)
                {
                    flag=1;
                    ans=i;
                }
                else
                {
                    rate=double(r)/double(i);
                    if (p<rate&&rate<q)
                    {
                        flag=1;
                        ans=i;
                    }
                }
            }
            printf("%d\n",ans);
        }
    };
    
    int main()
    {
        dts::main();
    }
    
  • 1
    @ 2020-06-17 16:01:31

    因为人数最多10000,所以可以直接枚举,然后判断是否能够满足范围,使得最小概率乘以人数上取整可以比最大概率乘以人数下取整小于等于,但是这个算法可能会有精度问题。

    但是,我要说的是,太坑了,同一套逻辑,JAVA在第六个点会出现精度问题,WA,但是CPP可以通过。
    气冷抖,JAVA什么时候才能真正站起来?!!

    JAVA

    状态 耗时 内存占用

    #1 Accepted 100ms 13.586 MiB
    #2 Accepted 100ms 13.707 MiB
    #3 Accepted 95ms 12.031 MiB
    #4 Accepted 94ms 12.309 MiB
    #5 Accepted 98ms 13.688 MiB
    #6 Wrong Answer 104ms 13.668 MiB
    #7 Accepted 97ms 13.602 MiB
    #8 Accepted 97ms 13.797 MiB
    #9 Accepted 97ms 12.066 MiB
    #10 Accepted 103ms 12.395 MiB

    CPP

    状态 耗时 内存占用

    #1 Accepted 1ms 256.0 KiB
    #2 Accepted 1ms 256.0 KiB
    #3 Accepted 1ms 256.0 KiB
    #4 Accepted 1ms 256.0 KiB
    #5 Accepted 1ms 256.0 KiB
    #6 Accepted 1ms 256.0 KiB
    #7 Accepted 1ms 256.0 KiB
    #8 Accepted 1ms 256.0 KiB
    #9 Accepted 1ms 256.0 KiB
    #10 Accepted 1ms 256.0 KiB

  • 1
    @ 2019-06-26 22:59:03
    //这道题显然使用二分来做,下面说一下二分的合理性
    //因为小数只有两位数,所以在p,q不相等时最多有1万人
    //p,q若相等,也最多有10万人(实际上到不了)
    //因此二分是完全可行的
    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main()
    {
        int i,l,r,mid,ans;
        double a,b,ha;
        cin>>a>>b;
        a=a/100.0;
        b=b/100.0;
        for(i=0;;i++)
        {
            l=1;
            r=i;
            ans=0;
            while(l<=r)
            {
                mid=(l+r)/2;
                ha=double(mid)/double(i);
                if(ha>a)
                 {
                    r=mid-1;
                    ans=mid;
                 }
                else
                 l=mid+1;
            }
            ha=double(ans)/double(i);
            if(ha<b)
             {
                cout<<i;
                return 0;
             }
        }
    }
    
  • 1
    @ 2014-01-27 11:36:19

    -0.000001就是考虑到i*p/100为整数的情况啦,这时的那个整数是不能取的。

  • 1
    @ 2012-08-05 22:18:53

    枚举整数i,直到int(q*i/100-0.00000001)-int(p*i/100+0.00000001)>=1的时候退出即可

  • 0
    @ 2017-10-15 16:16:12

    Accepted
    /usr/bin/ld.bfd: warning: /out/link.res contains output sections; did you forget -T?

    状态 耗时 内存占用

    #1 Accepted 1ms 256.0 KiB
    #2 Accepted 1ms 256.0 KiB
    #3 Accepted 1ms 256.0 KiB
    #4 Accepted 2ms 256.0 KiB
    #5 Accepted 1ms 256.0 KiB
    #6 Accepted 2ms 256.0 KiB
    #7 Accepted 1ms 256.0 KiB
    #8 Accepted 1ms 256.0 KiB
    #9 Accepted 1ms 256.0 KiB
    #10 Accepted 1ms 256.0 KiB
    代码
    var p,q,f1,f2:double;
    s:longint;
    begin
    readln(p,q);
    s:=1;
    while true do
    begin
    f1:=s*p/100;
    f2:=s*q/100;
    if(f1<trunc(f2))and(f2>trunc(f2))then
    begin
    writeln(s);
    halt;
    end;
    inc(s);
    end;
    end.

  • 0
    @ 2016-02-23 13:13:44

    题目 P1041 神风堂人数
    递交时间 2014-08-01 18:19:24
    代码语言 C++
    评测机 VijosEx
    消耗时间 30 ms
    消耗内存 272 KiB
    评测时间 2014-08-01 18:19:28
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    Accepted, time = 30 ms, mem = 272 KiB, score = 100

  • 0
    @ 2016-02-23 13:13:42

    题目 P1041 神风堂人数
    递交时间 2014-08-01 18:19:24
    代码语言 C++
    评测机 VijosEx
    消耗时间 30 ms
    消耗内存 272 KiB
    评测时间 2014-08-01 18:19:28
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    Accepted, time = 30 ms, mem = 272 KiB, score = 100

  • 0
    @ 2016-02-23 13:13:40

    题目 P1041 神风堂人数
    递交时间 2014-08-01 18:19:24
    代码语言 C++
    评测机 VijosEx
    消耗时间 30 ms
    消耗内存 272 KiB
    评测时间 2014-08-01 18:19:28
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    Accepted, time = 30 ms, mem = 272 KiB, score = 100

  • 0
    @ 2016-02-23 13:13:39

    题目 P1041 神风堂人数
    递交时间 2014-08-01 18:19:24
    代码语言 C++
    评测机 VijosEx
    消耗时间 30 ms
    消耗内存 272 KiB
    评测时间 2014-08-01 18:19:28
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    Accepted, time = 30 ms, mem = 272 KiB, score = 100

  • 0
    @ 2014-09-08 21:05:48

    P1041神风堂人数
    Accepted
    记录信息
    评测状态 Accepted
    题目 P1041 神风堂人数
    递交时间 2014-09-08 21:04:44
    代码语言 C++
    评测机 上海红茶馆
    消耗时间 45 ms
    消耗内存 564 KiB
    评测时间 2014-09-08 21:04:45
    评测结果

    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 564 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10

    测试数据 #3: Accepted, time = 0 ms, mem = 556 KiB, score = 10

    测试数据 #4: Accepted, time = 0 ms, mem = 556 KiB, score = 10

    测试数据 #5: Accepted, time = 15 ms, mem = 556 KiB, score = 10

    测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10

    测试数据 #7: Accepted, time = 0 ms, mem = 560 KiB, score = 10

    测试数据 #8: Accepted, time = 15 ms, mem = 564 KiB, score = 10

    测试数据 #9: Accepted, time = 15 ms, mem = 556 KiB, score = 10

    Accepted, time = 45 ms, mem = 564 KiB, score = 100
    代码

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <math.h>

    using namespace std;

    double p , q;
    double a , b;
    int c;
    int i;

    int main()
    {
    while( cin >> p >> q )
    {
    for( i = 1 ; ; i++ )
    {
    a = p * i / 100;
    b = q * i / 100;
    if( ( q * i /100 ) == floor( q * i /100 ) )
    c = q * i /100 - 1;
    else
    c = floor( q * i / 100 );
    //cout << a << " " << b << " " << c << endl;
    if( a < c && b > c )
    break;
    }
    cout << i << endl;
    }
    return 0;
    }

    用double代替float,不用考虑精度都可以。。。

  • 0
    @ 2014-08-05 14:37:32

    #include <stdio.h>
    #include <math.h>
    #define accuracy -0.00000001
    int main(){
    double bottom,top;
    long i;
    scanf("%lf %lf",&bottom,&top);
    bottom/=100.0;
    top/=100.0;
    for(i=1;floor(bottom*i)+1-top*i>=accuracy;i++)
    ;//nothing to do in this loop.
    printf("%ld\n",i);
    return 0;
    }

  • 0
    @ 2014-08-01 18:20:20

    1次

    记录信息
    评测状态 Accepted
    题目 P1041 神风堂人数
    递交时间 2014-08-01 18:19:24
    代码语言 C++
    评测机 VijosEx
    消耗时间 30 ms
    消耗内存 272 KiB
    评测时间 2014-08-01 18:19:28
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    Accepted, time = 30 ms, mem = 272 KiB, score = 100

  • 0
    @ 2014-06-20 23:31:10

    #include <cstdio>
    int main()
    { double p, q;
    scanf("%lf%lf", &p, &q);
    p/=100; q/=100;
    for (int i = 0;;i++)
    if (int(q*i-0.000001) - int(p*i+0.000001) >= 1)
    { printf("%d\n", i);
    return 0;
    }
    return 0;
    }
    出現了,0ms

  • 0
    @ 2014-05-08 21:50:53

    #include <iostream>
    using namespace std;
    int main(){
    int i;
    float p,q;
    cin>>p>>q;
    p/=100;
    q/=100;
    for (i=1;i<=32767;i++){
    if (int (q*i-0.000001)-int (p*i+0.000001)>=1){
    cout<<i;
    break;
    }
    }
    return 0;
    }

  • 0
    @ 2014-04-17 19:02:05

    第140道纪念

  • 0
    @ 2014-03-21 19:03:36

    水 70道纪念 特此发表

    var p,q,f1,f2:double;

    s:longint;

    begin

    readln(p,q);

    s:=1;

    while true do

    begin
    f1:=s*p/100;

    f2:=s*q/100;
    if(f1<trunc(f2))and(f2>trunc(f2))then

    begin

    writeln(s);

    halt;

    end;

    inc(s);

    end;

    end.

  • 0
    @ 2013-11-02 20:40:43

    为什么要+-0.000001

  • 0
    @ 2013-09-23 20:04:16

    好奇怪啊,real改成extended就能过。哪位仁兄能讲下原因?

信息

ID
1041
难度
6
分类
其他 | 数学 点击显示
标签
(无)
递交数
8175
已通过
2289
通过率
28%
被复制
4
上传者