CodeForces 7C Line】的更多相关文章

ax+by+c=0可以转化为ax+by=-c: 可以用扩展欧几里德算法来求ax1+by1=gcd(a,b)来求出x1,y1 此时gcd(a,b)不一定等于-c,假设-c=gcd(a,b)*z,可得z=-c/gcd(a,b); 则ax+by=-c <==> (ax1+by1)*z=gcd(a,b)z; <==> ax1*z+bx2*z=gcd(a,b)z; 因此可以得知x与x1的关系,y与y1的关系: x=x1*z,y = y1*z(z上面已经求出来了) #include<st…
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from  - 5·1018 to 5·101…
欧几里德定理: 对于整数a,b来说,gcd(a, b)==gcd(b, a%b)==d(a与b的最大公约数),又称为辗转相除法 证明: 因为a是d的倍数,b是d的倍数:所以a%d==0:b%d==0: 设k=a/b:r=a%b:则 a=k*b+r: 由上得出:r=a-k*b: 因为a和b都是d的倍数,所以(a-k*b)也是d的倍数,所以r也是d的倍数: 所以gcd(a, b)==gcd(b, a%b)==d 而为什么要证明gcd(a, b)==gcd(b, a%b)==d这个式子成立呢? 其实证…
题目链接 AC了.经典问题,a*x+b*y+c = 0整数点,有些忘记了扩展欧几里德,复习一下. #include <cstdio> #include <iostream> #include <cmath> using namespace std ; #define LL __int64 LL x,y; LL ext_eulid(LL a,LL b) { LL t,d; ) { x = ; y = ; return a; } d = ext_eulid(b,a%b);…
扩展欧几里得是计算 ax + by = gcd(a,b) 的 x,y的整数解. 现在是ax + by + c = 0; 只要 -c 是 gcd(a,b) 的整数倍时有整数解,整数解是 x = x*(-c)/gcd(a,b) ; y = y*(-c)/gcd(a,b); #include <bits/stdc++.h> using namespace std; typedef long long ll; void gcd(ll a,ll b,ll& d,ll& x,ll&…
B - 楼下水题 Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 7C Description A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coo…
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that ea…
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal. 输入 The first line contains integer n (1 ≤ n ≤ 3·105)…
Happy Line Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 549G Description Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this…
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/319/B Description There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who h…