2 solutions

  • 1
    @ 2025-6-12 22:35:54
    #include <iostream>
    using namespace std;
    int main(){
        int t;
        long long a,b,c,sum;
        cin>>t>>a>>b>>c;
        sum=a+b+c;
        if(t==1){
            cout<<sum/2;
        }else{
            cout<<sum;
        }
        return 0;
    }
    

    1.用一个变量来存储1或0(即小明今天是否有家长限制) 2.a,b,c三个变量由于答案可能会很大,应用 long long 3.用一个变量将a,b,c的值累和(可用可不用) 4.判定是否/2,后进行输出

    • 1
      @ 2025-5-28 19:05:50

      由于 a,b,ca,b,c 都是偶数,所以只需要在有限制的情况下输出 (a+b+c)/2(a+b+c)/2 否则输出 a+b+ca+b+c 即可

      #include <iostream>
      using namespace std;
      
      int main() {
          int r;
          long long a, b, c;
          
          cin >> r;
          cin >> a >> b >> c;
          
          long long total = a + b + c;
          
          if (r) {
              cout << total / 2 << endl;
          } else {
              cout << total << endl;
          }
          
          return 0;
      }
      
      • 1

      Information

      ID
      1492
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      6
      Tags
      (None)
      # Submissions
      146
      Accepted
      41
      Uploaded By