1 条题解

  • 0
    @ 2025-10-10 15:48:07

    C++ :

    #include <iostream>
    using namespace std;
    
    int main(){
    	int c = 1;	
    	double t = 2,s = 2,x;
    	cin>>x;
    	while(s < x){
    		t = t * 0.98;
    		s = s + t;
    		c++;
    	}
    	
    	cout<<c<<endl;
    }
    

    Java :

    
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
    //        int num1 = scanner.nextInt();
    //        int num2 = scanner.nextInt();
    //        int num3 = scanner.nextInt();
    //        int num4 = scanner.nextInt();
    //        int num5 = scanner.nextInt();
    
            double num1 = scanner.nextDouble();
    //        double num2 = scanner.nextDouble();
    //        double num3 = scanner.nextDouble();
            int m = 0;
            double x = 2.0;
    //        int a, b, c, d, m, count = 0;
            while(num1>0)
            {
                num1-=x;
                x*=0.98;
                m++;
            }
            System.out.println(m);
            }
    }
    
    

    Python :

    n = float(input())
    i = 0
    a = 2
    b = 0
    while(b < n):
        b += a
        a *= 0.98
        i += 1
    print(i)
    
    • 1

    信息

    ID
    440
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者