ZOJ - 4101 - Element Swapping (数学)
Posted jiaaaake
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZOJ - 4101 - Element Swapping (数学)相关的知识,希望对你有一定的参考价值。
题目大意: 有一个n个数的序列,交换其中两个Ai与Aj,给你交换前后的两种关系。 问有多少种情况。
题解 : https://blog.csdn.net/u011815404/article/details/89607866 (写的很好! 懒得写公式了。。。.)
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5+5; int T, n; ll a[maxn]; ll x, y, sum; map<int, int> cnt; int main() scanf("%d",&T); while(T--) cnt.clear(); sum = 0; scanf("%d%lld%lld",&n, &x, &y); for(int i = 1; i <= n; i++) scanf("%lld",&a[i]); cnt[a[i]]++; x -= 1ll * i * a[i]; y -= 1ll * i * a[i] * a[i]; if(x == 0) if(y != 0) printf("0\n"); continue; for(int i = 1; i <= n; i++) sum += cnt[a[i]]-1; else if(y % x != 0) printf("0\n"); continue; else ll num = y / x; for(int i = 1; i <= n; i++) ll Aj = num - a[i]; // cout << "Aj = " << Aj << endl; if(Aj == a[i]) continue; ll j = (x-Aj*i+a[i]*i)/(a[i]-Aj); // cout << "j = " << j << endl; if(j < 0) continue; if(a[j] == Aj) sum++; printf("%lld\n",sum/2); return 0;
以上是关于ZOJ - 4101 - Element Swapping (数学)的主要内容,如果未能解决你的问题,请参考以下文章
IPC-4202B,4103B,4104,4121,4101E,4203b,4024b,4412b
求助一个C语言问题 为啥在VC中老是提示我 warning C4101: 'c' : unreferenced local variable
TOJ4101.Guess Game(TOJ means Tianjin University Online Judge)(dp的思想,但这道题目是假dp)