poj3067】的更多相关文章

题目链接: https://vjudge.net/problem/POJ-3067 题目大意: 日本岛东海岸与西海岸分别有N和M个城市,现在修高速公路连接东西海岸的城市,求交点个数. 解题思路: 记每条告诉公路为(x,y), 即东岸的第x个城市与西岸的第y个城市修一条路.当两条路有交点时,满足(x1-x2)*(y1-y2) < 0.所以,将每条路按x从小到达排序,若x相同,按y从小到大排序. 然后按排序后的公路用树状数组在线更新,求y的逆序数之和 即为交点个数. 比如样例 1 42 33 23…
求交点的个数: 容易发现,对于两条航线(xi,yi)和(xj,yj),设xi<xj 只有yi>yj时两条航线存在交点: 于是我们考虑以x为第一关键字减序,y为第二关键字为减序排序: 则对于当前航线(xi,yi),只要找之前所有yj小于yi的个数 所有交点数就是其总和,统计就要用到飘逸的树状数组了~ ..] of longint;     x,y:..] of longint;     i,j,n,m,k,t:longint;     ans:int64; procedure add(p:lon…
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East coast and M cities on the West coast (M <= 1000, N <= 1000). K superhighways will be build. Cities on eac…
题目链接:http://poj.org/problem?id=3067 题目就是让我们求连线后交点的个数 很容易想到将左端点从小到大排序,如果左端点相同则右端点从小到大排序 那么答案即为逆序对的个数 用树状数组求解逆序对 代码: #include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> #include<algorithm> using namespace st…
题解是直接对一维升序排列,然后计算有树状数组中比二维小的点即可 但是对二维降序排列为什么不信呢?? /* */ #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; #define maxn 1010 #define ll long long int n,m,k; ll bit[maxn*maxn]; struct Edge…
题目链接:传送门 题意:日本有东城m个城市,西城m个城市,东城与西城相互连线架桥,判断这些桥相交的次数. 思路:两个直线相交就是(x1-x2)*(y1-y2)<0,所以,对x,y进行排序,按照x从小到大进行排序,x相同,按照y从小到大排序 然后x已经有序,判断y的逆序数.从大到小判断,因为如果从小到大(3,1)与(3,2)就算相交,从大到小可以避免这种情况. 注意: (1)数组要开大一点: (2)ans要用longlong类型,结果会很大. #include<iostream> #inc…
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3067">http://poj.org/problem? id=3067 Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East coast…
Japan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24151   Accepted: 6535 Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East coas…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26270   Accepted: 7132 Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East coast and…
Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East coast and M cities on the West coast (M <= 1000, N <= 1000). K superhighways will be build. C…