分析:做着感觉像脑筋急转弯一样......因为空间的限制,存不下每一个数,所以用数学方法来解.
设t1=Σai - Σbi = aj - bj,t2=Σi*ai - Σi*bi = j*(aj - bj).j是a,b不相等的位置,t2/t1就是答案了.
#include#include #include #include 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;}