跳到正文

题解

P1001 A+B Problem题解

meizhiyuan约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年5月12日
收录
2026年11月22日
更新
2026年11月22日
篇幅
约 1 分钟
题目
P1001

版本

  1. v1当前

https://www.luogu.com.cn/problem/P1001

不是那么奇葩的奇葩解

题目大意

输出a和b 求a+b的和;

正解:

C++
#include<bits/ctdc++.h>//万能头文件
using namespace std;
int main(){
    int a,b;//定义变量
    cin >> a >> b;//输入a与b
    cout << a+b;//输出和
    return 0;
}

新手勿看

“奇葩”の解答:

小巫见大巫

蒟蒻很菜,大佬勿喷;

其实只要用前缀和就能轻松解决这道题:

C++
#include <bits/stdc++.h>
using namespace std;
int a[10000010],sum[100000010];
int main(){
    for(int i=1;i<=2;i++){
        cin >> a[i];
        sum[i]=sum[i-1]+a[i];
    }
    cout << sum[2]-sum[0];
return 0;
}
原文