5 条题解

  • 1
    @ 2024-12-28 11:36:22
    #include<bits/stdc++.h>
    #define int double
    using namespace std;
    int n,ans;
    signed main(){
    	cin>>n;
    	n*=2.8;
    	while(1){
    		if(n<0.5)break;
    		n/=2;
    		ans++;
    	}
    	cout<<ans;
    }
    
    • 0
      @ 2024-12-28 15:08:51

      为了避免精度误差(说不定不用吧),实数判等应该用两个实数的差的绝对值是否小于一个很小的数(比如 10710^{-7})。

      #include<bits/stdc++.h>
      #define int long long
      #define INF 0x3f3f3f
      using namespace std;
      int n,ans;
      signed main(){
      	cin>>n;
      	double k=n*2.8;
      	while(k-0.5>0.0000001)k/=2,ans++;
      	cout<<ans;
      	return 0;
      }
      
      • 0
        @ 2024-12-25 20:04:09

        SO WATERRRRRRRRRRRRRRRRR

        #include<bits/stdc++.h>
        using namespace std;
        double s=1,n,v,h;
        int main(){
        	cin>>h;
        	h*=2.8;
        	for(int i=1;i<10;i++){
        		if(h/2<0.5){
        			cout<<i;
        			return 0;
        		}
        		h/=2;
        	}
        }
        
        • 0
          @ 2024-12-24 20:57:56

          其实就是告诉你几层楼然后你直接就能算出球掉下去的高度然后按照题面每次下落弹回来的高度是原来的一半直接干就完了。

          #include<bits/stdc++.h>
          using namespace std;
          int main()
          {
          	int n;
          	cin>>n;
          	double qwq=n*2.8;
          	int ans=0;
          	while(qwq>=0.5)//高度低于 0.5 才能输出
          	{
          		ans++;
          		qwq/=2;
          	}
          	cout<<ans;
          	return 0;
          }
          
          • 0
            @ 2024-12-22 11:03:53

            C++ :

            #include<bits/stdc++.h>
            using namespace std;
            double n;
            int a;
            int main()
            {
            cin>>n;
            n=n*2.8;
            while(n>=0.5)
            	{
            	a++;
            	n/=2;
            	}
            cout<<a;
            return 0;
            }
            

            Python :

            # coding=utf-8
            n=input()
            h=float(n)*2.8
            ans=0
            while (h>=0.5):
                h=h/2
                ans=ans+1
            print(ans)
            
            
            • 1

            信息

            ID
            17
            时间
            1000ms
            内存
            128MiB
            难度
            1
            标签
            递交数
            29
            已通过
            26
            上传者