解题思路:
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> PI; map<PI,int>M; map<PI,bool>vis; int gcd(int a,int b){ if(b==0) return a; else return gcd(b,a%b); } int n; int ans = 0; int main(){ cin >> n; for(int i = 1 ; i <= n ; i ++){ int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; int g = gcd(abs(x1-x2),abs(y1-y2)); int ax = (x2-x1)/g; int ay = (y2-y1)/g; while(x1 != x2 || y1 != y2){ M[PI(x1,y1)]++; if(M[PI(x1,y1)] >= 2 && !vis[PI(x1,y1)]){ ans ++; vis[PI(x1,y1)] = 1; } x1 += ax; y1 += ay; } M[{x2,y2}]++; if(M[PI(x2,y2)] >= 2&& !vis[PI(x2,y2)]){ ans ++; vis[PI(x2,y2)] = 1; } } cout << ans <<endl; return 0; }
0.0分
3 人评分
简单的a+b (C语言代码)浏览:445 |
蓝桥杯历届试题-翻硬币 (C++代码)浏览:947 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:620 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:629 |
用筛法求之N内的素数。 (C语言代码)浏览:590 |
陶陶摘苹果2 (C语言代码)浏览:640 |
C语言程序设计教程(第三版)课后习题12.1 (C语言代码)浏览:682 |
C语言训练-大、小写问题 (C语言代码)浏览:714 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:487 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:745 |