3 条题解

  • 1
    @ 2025-10-22 19:46:49

    注:整活题解!

    基于自己的题解 Solu_A+B_Problem 修改 我们很容易想到用动态规划解决本题(?
    思路见上面那片题解 代码如下:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    int dp(int a, int b) {
        int target = a + b;
        if (target == 0) return 0;
        unordered_map<int, int> dp;
        dp[0] = 0;
    
        if (target > 0) {
            // 目标为正数:从0递推到target(每次+1)
            for (int i = 1; i <= target; ++i) {
                dp[i] = dp[i - 1] + 1;
            }
        } else {
            // 目标为负数:从0递推到target(每次-1)
            for (int i = -1; i >= target; --i) {
                dp[i] = dp[i + 1] - 1;
            }
        }
        return dp[target];
    }
    
    
    int main() {
        
        int a,b;
    	while(cin>>a>>b)//易证本题数组无需清空(?
    	cout<<dp(a,b)<<"\n";
    
        return 0;
    }
    
    
    • 1
      @ 2025-10-4 10:45:51

      考虑模拟。

      显然的代码如下:

      long long a, b;
      while(cin >> a >> b)
          cout << a + b << endl;
      
      • 1
        @ 2025-10-3 12:38:32

        这道题没什么好讲的。

        while(cin >> a >> b) 可以不停输入 aabb 直到结束。

        其他直接模拟。

        • 1

        信息

        ID
        40
        时间
        1000ms
        内存
        32MiB
        难度
        10
        标签
        递交数
        5
        已通过
        5
        上传者