HDU5084 HeHe·找规律

规律如下:
在这里插入图片描述

找规律

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll a[N];
int n,m;
int main(){
    while(~scanf("%d",&n)){
        for (int i = 1; i <= 2*n-1; ++i) {
            scanf("%lld",&a[i]);
        }
        ll ans=0;
        scanf("%d",&m);
        for (int i = 1,x,y,t=0; i <= m; ++i) {
            scanf("%d%d",&x,&y);
            x=(x+t)%n;
            y=(y+t)%n;
            ll res=0;
            for (int j = 1; j <= n; ++j) {
                res+=a[n-x+j-1]*a[n+y-j+1];
            }
            t=res;
            ans+=res;
        }
        cout<<ans<<endl;
    }
    return 0;
}
发布了34 篇原创文章 · 获赞 0 · 访问量 959

猜你喜欢

转载自blog.csdn.net/Yubing792289314/article/details/104185245