日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Periodic Signal

發布時間:2024/8/23 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Periodic Signal 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

描述

Profess X is an expert in signal processing. He has a device which can send a particular 1 second signal repeatedly. The signal is A0 ...?An-1?under n Hz sampling.

One day, the device fell on the ground accidentally. Profess X wanted to check whether the device can still work properly. So he ran another n Hz sampling to the fallen device and got B0 ...?Bn-1.

To compare two periodic signals, Profess X define the DIFFERENCE of signal A and B as follow:

You may assume that two signals are the same if their DIFFERENCE is small enough.?
Profess X is too busy to calculate this value. So the calculation is on you.

輸入

The first line contains a single integer T, indicating the number of test cases.

In each test case, the first line contains an integer n. The second line contains n integers, A0 ...?An-1. The third line contains n integers, B0 ...?Bn-1.

T≤40 including several small test cases and no more than 4 large test cases.

For small test cases, 0<n≤6?103.

For large test cases, 0<n≤6?104.

For all test cases, 0≤Ai,Bi<220.

輸出

For each test case, print the answer in a single line.

樣例輸入
2 9 3 0 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 5 1 2 3 4 5 2 3 4 5 1
樣例輸出
80

0

#include <iostream> #include <cmath> #include <vector> #include <cstdlib> #include <cstdio> #include <climits> #include <ctime> #include <cstring> #include <queue> #include <stack> #include <list> #include <algorithm> #include <map> #include <set> #define LL long long #define Pr pair<int,int> #define fread(ch) freopen(ch,"r",stdin) #define fwrite(ch) freopen(ch,"w",stdout)using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9+7; const double eps = 1e-3; const int maxn = 61234;struct Line {LL l,r,val;bool operator <(const struct Line a)const{return l < a.l;} } ln[maxn];LL bit[maxn]; LL st,en,t; int n,m,tp; LL to[maxn]; map <LL,int> mp; int id,iid;int Lowbit(int x) {return x&(-x); }void Add(int x,LL ad) {x++;while(x <= id+1){bit[x] += ad;x += Lowbit(x);} }LL Sum(int x) {LL ans = 0;x++;while(x){ans += bit[x];x -= Lowbit(x);}return ans; }int Search(LL x) {int l,r;l = 0,r = id;int ans = -1;while(l <= r){int mid = (l+r)>>1;if(to[mid] <= x){ans = mid;l = mid+1;}else r = mid-1;}return ans; }LL solve() {LL mx = 0;memset(bit,0,sizeof(bit));sort(ln,ln+tp);int l,r;l = 0,r = 0;for(int i = 0; i <= id; ++i){int rr = Search(to[i]+t);while(r < tp && mp[ln[r].l] <= rr){Add(mp[ln[r].r],ln[r].val);++r;}while(l < tp && mp[ln[l].l] < i){Add(mp[ln[l].r],-ln[l].val);++l;}mx = max(mx,Sum(rr)); // ? ? ? ?printf("%d,%d %lld\n",i,rr,mx); // ? ? ? ?printf("%d %d\n",l,r-1);}return mx; }int main() {LL t2,x,y,val,sum;while(~scanf("%lld%lld",&t,&t2)){mp.clear();iid = 0;scanf("%lld",&st);en = st+t2;scanf("%d%d",&n,&m);tp = 0;sum = 0;for(int i = 0; i < n; ++i){scanf("%lld%lld%lld",&x,&y,&val);x += y;if(st <= x && x <= en){ln[tp].l = x+y;ln[tp].r = (en-x)/(2*y)*(2*y)+ln[tp].l;ln[tp++].val = val;sum += val;to[iid++] = ln[tp-1].l;to[iid++] = ln[tp-1].r; // ? ? ? ? ? ? ? ?printf("%lld %lld\n",ln[tp-1].l,ln[tp-1].r);}}for(int i = 0; i < m; ++i){scanf("%lld%lld%lld",&x,&y,&val);ln[tp].l = x+y;if(st <= x+2*y && x+2*y <= en){ln[tp].r = (en-x)/(2*y)*(2*y)+ln[tp].l;}else ln[tp].r = x+y;ln[tp++].val = val;sum += val;to[iid++] = ln[tp-1].l;to[iid++] = ln[tp-1].r;}sort(to,to+iid);id = -1;for(int i = 0; i < iid; ++i){if(!i || to[i] != to[i-1]){++id;to[id] = to[i];mp[to[i]] = id;}}printf("%lld\n",sum-solve());}return 0; }

總結

以上是生活随笔為你收集整理的Periodic Signal的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。