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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Countries

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

描述

There are two antagonistic countries, country A and country B. They are in a war, and keep launching missiles towards each other.

It is known that country A will launch N missiles. The i-th missile will be launched at time Tai. It flies uniformly and take time Taci from one country to the other. Its damage capability is Dai.

It is known that country B will launch M missiles. The i-th missile will be launched at time Tbi.

It flies uniformly and takes time Tbci?from one country to the other. Its damage capability is Dbi.

Both of the countries can activate their own defending system.

The defending system of country A can last for time TA, while The defending system of country B can last for time TB.

When the defending system is activated, all missiles reaching the country will turn around and fly back at the same speed as they come.

At other time, the missiles reaching the country will do damages to the country.
(Note that the defending system is still considered active at the exact moment it fails)

Country B will activate its defending system at time X.

When is the best time for country A to activate its defending system? Please calculate the minimal damage country A will suffer.

輸入

There are no more than 50 test cases.

For each test case:

The first line contains two integers TA?and TB, indicating the lasting time of the defending system of two countries.

The second line contains one integer X, indicating the time that country B will active its defending system.

The third line contains two integers N and M, indicating the number of missiles country A and country B will launch.

Then N lines follow. Each line contains three integers Tai, Taci?and Dai, indicating the launching time, flying time and damage capability of the i-th missiles country A launches.

Then M lines follow. Each line contains three integers Tbi, Tbci?and Dbi, indicating the launching time, flying time and damage capability of the i-th missiles country B launches.

0 <= TA, TB, X, Tai, Tbi<= 100000000

1 <= Taci, Tbci?<= 100000000

0 <= N, M <= 10000

1 <= Dai, Dbi?<= 10000

輸出

For each test case, output the minimal damage country A will suffer.

提示

In the first case, country A should active its defending system at time 3.

Time 1: the missile is launched by country A.

Time 2: the missile reaches country B, and country B actives its defending system, then the missile turns around.

Time 3: the missile reaches country A, and country A actives its defending system, then the missile turn around.

Time 4: the missile reaches country B and turns around.

Time 5: the missile reaches country A and turns around.

Time 6: the missile reaches country B, causes damages to country B.


樣例輸入
2 2 2 1 0 1 1 10 4 5 3 2 2 1 2 10 1 5 7 1 3 2 0 4 8
樣例輸出
0

17

#include <cmath> #include <ctime> #include <cctype> #include <cstdio> #include <cstring> #include <cstdlib> #include <cassert> #include <set> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <complex> #include <iostream> #include <algorithm> #define rep(i,s,t) for(register LL i=s,_t=t;i<_t;++i) #define per(i,s,t) for(register LL i=t-1,_s=s;i>=_s;--i) using namespace std; #define LL long long const LL mod=(LL)1e9+7,inf=0x7fffffff; const LL INF=1ll<<60;const LL P=31525197391593473,r=3;void mod_add(LL &a,LL b){if((a+=b)>=P)a-=P; } void mod_minus(LL &a,LL b){if((a-=b)<0)a+=P; } LL mul(LL x,LL y,LL z){ return (x*y - (LL)(x/(long double)z*y+1e-3)*z+z)%z; }LL fast_mod_pow(LL a,LL b){LL res=1;for(;b;b>>=1,a=mul(a,a,P))if(b&1)res=mul(res,a,P);return res; }inline LL calc_inv(LL x){return fast_mod_pow(x,P-2); }const LL N=(1<<18)+5; LL rev[N],A[N],B[N],C[N];void DFT(LL *arr,LL n,bool flag){rep(i,0,n)if(i<rev[i])swap(arr[i],arr[rev[i]]);for(LL m=2;m<=n;m<<=1){LL g=fast_mod_pow(r,(P-1)/m);if(flag)g=calc_inv(g);for(LL i=0;i<n;i+=m){LL cur=1;rep(j,0,m>>1){LL x=arr[i+j],y=mul(cur,arr[i+j+(m>>1)],P);mod_add(arr[i+j]=x,y);mod_minus(arr[i+j+(m>>1)]=x,y);cur=mul(cur,g,P);}}} } void NTT(LL n,LL m){LL _n,S;for(_n=1,S=0;_n<n+m;_n<<=1,++S);rep(i,1,_n)rev[i]=(rev[i>>1]>>1)|((i&1)<<S-1);rep(i,n,_n)A[i]=0;rep(i,m,_n)B[i]=0;DFT(A,_n,false);DFT(B,_n,false);rep(i,0,_n)C[i]=mul(A[i],B[i],P);DFT(C,_n,true);LL inv=calc_inv(_n);rep(i,0,_n)C[i]=mul(C[i],inv,P); }int main() {LL T;scanf("%lld",&T); LL n; while(T-- && ~scanf("%lld",&n)){ long long ans = 0; for(LL i = 0;i < n;i++){scanf("%lld",&A[i]);ans += 1ll * A[i] * A[i]; } for(LL i = 0;i < n;i++){scanf("%lld",&B[i]);ans += 1ll * B[i] * B[i]; } for(LL i = 0;i < n;i++) A[i+n] = A[i];reverse(B,B+n); NTT(n*2,n); ans -= *max_element(C+n,C+n*2 + 1) * 2; printf("%lld\n",ans); }return 0; }

總結

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

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