日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

【2019浙江省赛 - B】Element Swapping(思维,数学)

發(fā)布時間:2023/12/10 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【2019浙江省赛 - B】Element Swapping(思维,数学) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

DreamGrid has an integer sequence??and he likes it very much. Unfortunately, his naughty roommate BaoBao swapped two elements??and??() in the sequence when DreamGrid wasn't at home. When DreamGrid comes back, he finds with dismay that his precious sequence has been changed into?!

What's worse is that DreamGrid cannot remember his precious sequence. What he only remembers are the two values

Given the sequence after swapping and the two values DreamGrid remembers, please help DreamGrid count the number of possible element pairs??BaoBao swaps.

Note that as DreamGrid is poor at memorizing numbers, the value of??or??might not match the sequence, and no possible element pair can be found in this situation.

Two element pairs??() and??() are considered different if??or?.

Input

There are multiple test cases. The first line of the input contains an integer?, indicating the number of test cases. For each test case:

The first line contains three integers?,??and??(), indicating the length of the sequence and the two values DreamGrid remembers.

The second line contains??integers??(), indicating the sequence after swapping. It's guaranteed that??and?.

It's guaranteed that the sum of??of all test cases will not exceed?.

Output

For each test case output one line containing one integer, indicating the number of possible element pairs BaoBao swaps.

Sample Input

2 6 61 237 1 1 4 5 1 4 3 20190429 92409102 1 2 3

Sample Output

2 0

Hint

For the first sample test case, it’s possible that BaoBao swaps the 2nd and the 3rd element, or the 5th and the 6th element.

解題報告:

兩數(shù)作差不難發(fā)現(xiàn),y的差除以x的差,就是a[i]+a[j],,所以分情況討論就行了。注意除數(shù)為0的情況和x相同y不相同的時候(好坑啊、、)

(%%%wjh大佬)

AC代碼:

#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<stack> #include<map> #include<set> #include<string> #include<vector> using namespace std; typedef long long ll; //ll f[1000]; ll a[200000],b[200000]; map<ll,ll> mp; map<ll,ll> ::iterator it; int main() {int t;cin>>t;while(t--){mp.clear();ll n,x,y;scanf("%lld%lld%lld",&n,&x,&y);for(int i=1;i<=n;i++){scanf("%lld",&a[i]);mp[a[i]]++;b[i]=a[i]*a[i];}ll x2=0,y2=0;for(ll i=1;i<=n;i++){x2+=a[i]*i;y2+=b[i]*i;}if(x==x2){if(y!=y2){puts("0");continue;} ll ans=0;for(it=mp.begin();it!=mp.end();it++){ll num=it->second;ans+=num*(num-1)/2;}printf("%lld\n",ans);continue;}ll ans=0;if(abs(y-y2)%abs(x-x2)!=0){puts("0");continue;}ll tmp=(y-y2)/(x-x2);ll dx=x-x2;ll dy=y-y2;for(int i=1;i<=n;i++){ll aj=tmp-a[i];ll dt=a[i]-aj;ll dij;if(dt==0){continue;}if(abs(dx)%abs(dt)!=0)continue;dij=dx/dt;ll wj=i+dij;if(wj<=i) continue;if(aj==a[wj]&&(x==(x2+wj*a[i]+i*a[wj]-i*a[i]-wj*a[wj]))&&(y==(y2-i*b[i]-wj*b[wj]+wj*b[i]+i*b[wj])))ans++;elsecontinue;}printf("%lld\n",ans);}return 0; } /* 8 6 61 237 1 1 4 5 1 4 3 20190429 92409102 1 2 3 */

?

總結(jié)

以上是生活随笔為你收集整理的【2019浙江省赛 - B】Element Swapping(思维,数学)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。