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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

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

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

題干:

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.

解題報告:

兩數作差不難發現,y的差除以x的差,就是a[i]+a[j],,所以分情況討論就行了。注意除數為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 */

?

總結

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

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