3 条题解

  • 1
    @ 2024-12-31 11:30:53

    ``

    #include<iostream>
    using namespace std;
    int main()
    {
    int a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;
    int count;
    double i;//只有double才能把所有的结果都表达
    if(b==0)
    {
    return 0;
    }
    for(i=0;i<=10000;i++)
    {
    double y=-(a*i+c)/b;//这里用double y来接收;
    int t=int(y);  //t是为了剔除小数的情况
    if(y>=0&&y-t==0)//根据题意写判断条件
    {
    count++;
    }
    }
    cout<<count;
    }
    这种做法可能不是很严谨,如果你会二分查找的话,可以试试对不对
    
    • 1
      @ 2023-8-26 17:23:05

             \ \ \ \ \ \ \ r是余数,ans记录答案,其他字母意义和题目中相同。

      #include <cstdio>
      #define RI register int
      
      int main(){
          int a, b, c, y, r, ans = 0;
          scanf("%d %d %d", &a, &b, &c);
          for(RI x = 0; x <= 10000; x++){
              y = ((-c) - x * a) / b;
              r = ((-c) - x * a) % b;
              if((!r) && (0 <= y) && (y <= 10000)){
                  ans ++;
              }
          }
          printf("%d", ans);
          return 0;
      }
      
      • 0
        @ 2025-9-24 18:59:21

        枚举法求,可以作为对拍

        #include <stdio.h> int main() { int a,b,c; scanf("%d %d %d",&a,&b,&c); int x,y,cnt; cnt=0; for(x=0;x<=10000;x++){ for(y=0;y<=10000;y++){ if(ax+by+c==0){ cnt++; } } } printf("%d",cnt); return 0; }

        
        
        • 1

        信息

        ID
        82
        时间
        1000ms
        内存
        128MiB
        难度
        6
        标签
        (无)
        递交数
        1107
        已通过
        329
        上传者