标签:class lld 一个 9.png using str turn ges ace
分析:做着感觉像脑筋急转弯一样......因为空间的限制,存不下每一个数,所以用数学方法来解.
设t1=Σai - Σbi = aj - bj,t2=Σi*ai - Σi*bi = j*(aj - bj).j是a,b不相等的位置,t2/t1就是答案了.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int T, n; long long a, b; int main() { scanf("%d", &T); while (T--) { a = b = 0; scanf("%d", &n); for (long long i = 1; i <= n; i++) { long long t; scanf("%lld", &t); a += t; b += i*t; } for (long long i = 1; i <= n; i++) { long long t; scanf("%lld", &t); a -= t; b -= i*t; } if (!a) printf("0\n"); else printf("1 %lld\n", b / a); } return 0; }
标签:class lld 一个 9.png using str turn ges ace
原文地址:http://www.cnblogs.com/zbtrs/p/7747371.html