7 条题解

  • 4
    @ 2023-11-21 18:59:17

    一道简单的模拟题

    #include <cstdio>
    using namespace std;
    int main()
    {
        int m, n, h, day = 0, sum = 0;
        scanf("%d%d%d", &m, &n, &h);
        while (sum < h)
        {
            sum += m;
            if (sum >= h)
            {
                printf("%d", day + 1);
                return 0;
            }
            day++;
            sum -= n;
        }
        return 0;
    }
    
    • 1
      @ 2022-12-10 9:55:33
      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int m, n, h, i, j;
      	cin >> m >> n >> h;
      	i = 0;
      	j = 0; 
      	while (true)
          {
      		i = i + m;
      		j = j + 1;
      		if (i >= h)
              {
      			break;
      		}
      		i = i - n;
      	}
      	cout << j << endl;
          return 0;	
      }//代码已AC
      
      • 0
        @ 2024-5-8 21:25:51
        #include <bits/stdc++.h>
        using namespace std;
        int n,m,h;
        int day,he;
        int main(){
        	cin>>n>>m>>h;
        	if (n<m)return 0;
        	while (true){
        		he+=n;
        		if (he>=h){
        			cout<<day+1;
        			return 0;
        		}
        		he-=m;
        		day++;
        	}
        	return 0;
        }
        
        • 0
          @ 2023-7-29 22:12:14

          一道简单的公式题

          AC代码:

          #include <bits/stdc++.h>
          using namespace std;
          int m,n,h;
          int main()
          {
              cin>>m>>n>>h;
              cout<<(h-n)/(m-n)+1;//快速公式
              return 0;
          }
          
          • 0
            @ 2023-7-7 13:30:18

            #include <iostream> using namespace std; int main() { int m, n, h; cin >> m >> n >> h; int num = 0; int sum = 0; while (1) { if (m + sum < h) { sum += m - n; num++; } if (m + sum >= h) { num++; break; } } cout << num; return 0; }

            • 0
              @ 2023-6-27 14:44:55

              解法1:模拟解

              #include <cstdio>
              using namespace std;
              
              int main()
              {
                  // 定义变量
                  unsigned char i = 0; // 用于记录循环次数的变量
                  unsigned char j, m, n, h; // 分别表示初始值、增量、目标值
              
                  // 输入初始值、增量、目标值
                  scanf("%hhu%hhu%hhu", &m, &n, &h);
              
                  // 初始化初始值
                  j += n;
              
                  // 循环递增计算,直到超过目标值
                  while (j < h) {
                      j -= n; // 减去增量
                      j += m; // 加上增量
                      ++i; // 记录循环次数
                  }
              
                  // 输出结果
                  printf("%hhu", i);
              
                  return 0;
              }
              

              解法2:公式解

              #include <cstdio>
              using namespace std;
              
              int main()
              {
                  // 定义变量
                  unsigned char m, n, h,o; // 分别表示初始值、增量、目标值
              
                  // 输入初始值、增量、目标值
                  scanf("%hhu%hhu%hhu", &m, &n, &h); 
                  
                  //使用公式计算
                  o=(h-n)/(m-n)+1;
                  
                  // 输出结果
                  printf("%hhu", o);
              
                  return 0;
              }
              
              • 0
                @ 2023-6-27 13:03:07
                #include "iostream"
                using namespace std;
                int main()
                {
                    int m,n,h;    //定义变量
                    cin >>m>>n>>h;   //输入变量
                    cout << (h-n)/(m-n)+1;   //运用公式进行计算
                }
                

                公式运行最快的一种方式,如果能用公式解决就尽量用公式,虽然这次的公式有点奇怪,和正常公式多了个加1。但还是尽量用公式更好,运行速度编译速度和编写速度都能翻个倍

                </span>
                • 1

                信息

                ID
                75
                时间
                1000ms
                内存
                16MiB
                难度
                2
                标签
                递交数
                154
                已通过
                100
                上传者