4 条题解

  • 2
    @ 2025-1-15 17:50:38
    #include<bits/stdc++.h>//"尝试"法
    using namespace std;
    int main(){
        int n,x,y;
        scanf("%d %d %d",&n,&x,&y);//读入,也可以换成cin
        if (y % x == 0){//特判虫子能不能正好吃完y / x个苹果
            cout << n - y / x;
            return 0;//提前结束,避免干扰后面操作
        }
        int cnt = 0;
        while (y >= x){//尝试
            cnt++;
            y-=x;
        }
        cout << n - cnt - 1;//别忘了,题目说的是完整的苹果
        return 0;
    }
    

    经过思考后,不难发现,尝试部分可换为算式:

    #include<bits/stdc++.h>//"算式"法
    using namespace std;
    int main(){
    	int n,x,y;
    	scanf("%d %d %d",&n,&x,&y);
    	if (y % x == 0){//还是特判
    		cout << n - y / x;
    	}else{
    		int remainder = n - y / x - 1;//remainder:剩余苹果
    		cout << remainder;	
    	}
    	
    	return 0;
    }
    
    • 1
      @ 2025-2-13 20:50:51

      #include<bits/stdc++.h> using namespace std; int main(){ int n,x,y; cin>>n>>x>>y; n-=y/x+1; cout<<n; }

      • 1
        @ 2025-1-26 8:53:26

        #include <bits/stdc++.h> using namespace std;

        int main(){ int n,s; double x,y; cin>>n>>x>>y; s=n-ceil(y*1.0/x); if(s<0) s=0; cout<<s; return 0; } 简单题解来啦~

        • 1
          @ 2025-1-15 15:25:09

          #include<bits/stdc++.h>

          using namespace std;

          int main(){

          double n,x,y,rest;
          
          cin>>n>>x>>y;
          
          rest=(n-ceil(y/x));
          
          if(rest<0)
          
          cout<<0;
          
          else
          
          cout<<rest;
          
          return 0;
          

          }

          • 1

          信息

          ID
          39
          时间
          1000ms
          内存
          128MiB
          难度
          2
          标签
          (无)
          递交数
          92
          已通过
          59
          上传者