E. Covered Points

利用克莱姆法则计算线段交点。n^2枚举,最后把个数开方,从ans中减去。

ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算。

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'
//#define R register
#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /*-----------------------showtime----------------------*/ const int maxn = ;
struct node{
ll x1,y1,x2,y2;
}a[maxn];
ll ans = ;
map<pii, int> mp; void cal(int i,int j){ ll x1 = a[i].x1,y1 = a[i].y1,x2 = a[i].x2,y2 = a[i].y2; ll x3 = a[j].x1,y3 = a[j].y1,x4 = a[j].x2,y4 = a[j].y2; ll a = (y1-y2) * (x4-x3) - (x2-x1)*(y3-y4);
ll t = (x2*y1 - x1*y2)*(x4-x3) - (x2-x1)*(x4*y3 - x3*y4);
ll p = (y1-y2) * (x4*y3-x3*y4) - (x2*y1-x1*y2)*(y3-y4); if(a == )return;
if(t % a || p % a) return;
t = t/a; p = p/a; if(x1 > x2) swap (x1,x2); if(t < x1 || t > x2) return; if(x3 > x4) swap (x3,x4); if(t < x3 || t > x4) return; if(y1 > y2) swap(y1,y2); if(p < y1 || p > y2) return; if(y3 > y4) swap(y3,y4); if(p < y3 || p > y4) return; mp[pii(t,p)] ++;
}
int main(){
int n; scanf("%d", &n);
for(int i=; i<=n; i++){
ll x1,y1,x2,y2;
scanf("%lld%lld%lld%lld", &x1, &y1, &x2, & y2);
a[i] = (node){x1,y1,x2,y2};
ll d1 = abs(x1 - x2);
ll d2 = abs(y1 - y2);
ans += __gcd(d1, d2) + ;
} for(int i=; i<=n; i++){
for(int j=; j<=n; j++){
if(i == j) continue;
cal(i,j);
}
} for(auto p : mp){
ans -= (int)sqrt(p.se);
}
printf("%lld\n", ans); return ;
}

最新文章

  1. C++基础_总结
  2. C#中WinForm窗体事件的执行次序
  3. EC笔记,第一部分:3.尽量使用const
  4. apache日志文件详解和实用分析命令
  5. 10个android开源项目
  6. EF5.0 对一个或多个实体的验证失败。有关详细信息,请参见“EntityValidationErrors”属性
  7. Python读取ini配置文件
  8. PAT (Advanced Level) 1016. Phone Bills (25)
  9. 同步中的四种锁synchronized、ReentrantLock、ReadWriteLock、StampedLock
  10. node.js之调试器
  11. 从零开始配置TypeScript + React + React-Router + Redux + Webpack开发环境
  12. NodeJS网络爬虫
  13. Oracle 时间字段显示不正确,类型错误
  14. Python学到什么程度就可以去找工作?掌握这4点足够了!
  15. 《程序猿闭门造车》之NBPM工作流引擎 - 开篇
  16. Egret 获取不到皮肤中的按钮 id
  17. 从MongoDB里面取得json格式的数据,然后存为本地的json文件,然后再从json读取变为dict
  18. BZOJ3590 SNOI2013Quare(状压dp)
  19. ASP.NET Core ef启用数据迁移
  20. OpenGL资料

热门文章

  1. perspective transform透视矩阵快速求法+矩形矫正
  2. dz6.0的一个sql注入漏洞
  3. MyBatis 框架 基础应用
  4. hdu 6397 Character Encoding (生成函数)
  5. tab选项卡代码
  6. Appium+python自动化(二十八)- 滑呀滑,滑到奈何桥喝碗孟婆汤 - 高级滑动(超详解)
  7. STL set 详细用法
  8. 控制台基于Quartz.Net组件实现定时任务调度(一)
  9. 给面试官讲明白:一致性Hash的原理和实践
  10. Redis集群与spring的整合