POJ 3067 Japan (tree-like array && control variables)

Source: Internet
Author: User

Test Instructions: there are N (1~n) and M (1~m) cities on the West coast and the east Coast, the cities of two coasts are connected by K-roads, roads intersect, and now information about cities and highways asks how many intersections you have of complex traffic made up of these highways ( If the starting point or the end point of the two highways are the same, then these two points do not intersect.

Analysis: The first analysis of the problem cases can be known when y1>y2, this is sure to have intersections. According to this feature you can quickly find that this is a reverse order of the problem. But it is not entirely correct, because the analysis of the answer is 6, the result is wrong. Now in the analysis is where the error, is (3,1) and (3,2) The problem here, the analysis of the topic, if the beginning or end of the same is not considered a banana, so it can be concluded that if X is equal, reverse order does not exist, the value of Y will be reversed. At the same time we can also find that these properties are in the X in ascending order of the case, so now the problem is very simple to solve, according to the X ascending row, equal words in ascending order of Y, and then the reverse of the pair.

#include <stdio.h>#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<Set>#defineLL Long Long#defineLowbit (i) (i& (-i))using namespacestd;intc[1001], N, K, m;voidAddintIintval) {     while(i<=m) {C[i]+=Val; I+=lowbit (i); }}ll sum (inti) {LL ans=0;  while(i>0) {ans+=C[i]; I-=lowbit (i); }    returnans;}structno{intx, y;} arr[10000000];BOOLcmpConstNo fir,ConstNo sec) {    if(fir.x = = sec.x)returnFir.y <sec.y; returnFir.x <sec.x;}intMainvoid){    intncase; scanf ("%d", &ncase);  for(intt=1; t<=ncase; t++) {memset (c,0,sizeof(c)); scanf ("%d%d%d", &n, &m, &k);  for(intI=0; i<k; i++) {scanf ("%d%d", &arr[i].x, &arr[i].y); } sort (arr, arr+K, CMP); LL ans=0;  for(intI=0; i<k; i++) {ans+ = i-sum (ARR[I].Y); Add (ARR[I].Y,1); } printf ("Test Case%d:%lld\n", T, ans); }    return 0;}
View Code

POJ 3067 Japan (tree-like array && control variables)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.