逆向思维,两轮变一轮
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define fep(i,a,b) for(int i=b;i>=a;--i)
using namespace std;
const int N = 1e6+5;
int n, a[N];
int main()
{
ios;
cin>>n;
rep(i,1,n) cin >> a[i];
int res=a[n];
fep(i,1,n-1) res=abs(res-a[i]);
cout << res;
}
原文:
https://blog.csdn.net/messywind/article/details/116275507