文章

68

粉丝

691

获赞

24

访问

546.3k

头像
题解来了
P1073
发布于2020年5月11日 12:33
阅读数 7.9k

https://blog.csdn.net/csyifanZhang/article/details/106051633

↑完整题解

 

#define MAX 1005
#define inf 0x3fffff
#define ll double
#define vec vector
#define PA pair

struct P {
	ll x, y;
}a[MAX];

int main() {
	ll n;
	while (cin >> n) {
		map m;//记录已经出现过的直线
		ll res = 0, cnt = 0;
		for (int i = 0; i < n; i++)
			cin >> a[i].x >> a[i].y;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				//两点确定一条直线
				cnt = 0;
				ll x = a[i].x - a[j].x, y = a[i].y - a[j].y;
				if (m[PA(x, y)] == 1)continue;//已经统计过了
				m[PA(x, y)] = m[PA(-x, -y)] = 1;
				for (int k = 0; k < n; k++) {
					ll tx = a[k].x - a[i].x, ty = a[k].y - a[i].y;
					if (tx*y - ty * x == 0)cnt++;
				}
				if (cnt > res)res = cnt;
			}
		}
		cout << res << endl;
	}
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发