Japan
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 21769 |
|
Accepted: 5885 |
Description
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must is built for the venue. Japan is Tall island with N cities on the East coast and M cities on the West coast (M <=, N <= 1000). K superhighways would be build. Cities on each coast is numbered 1, 2, ... Each superhighway are straight line and connects city in the East coast with city of the West coast. The funding for the construction are guaranteed by ACM. A major portion of the sum is determined by the number of crossings between superhighways. At the most of the superhighways cross at the one location. Write A program that calculates the number of the crossings between superhighways.
Input
The input file starts with t-the number of test cases. Each test case is starts with three numbers–n, M, K. Each of the next K lines contains, numbers–the numbers of cities connected by the superhighway. The first one is the number of the city on the East coast and second one are the number of the city of the West coast.
Output
For each test case, write one line in the standard output:
Test Case Number: (Number of crossings)
Sample Input
13 4 41 42 33 23 1
Sample Output
Test Case 1:5
Sequence, convert to reverse number
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib > #include <cmath> #include <algorithm>using namespace std; #define N 2010int tt,n,m,k,c[n];struct node{in T X,y,pos;} E[n*n];bool CMP (node A,node b) {if (a.x!=b.x) return a.x<b.x; Return a.y<b.y;}; int lowbit (int x) {return x& (-X);} void update (int pos,int m) {while (pos<n) {c[pos]+=m; Pos+=lowbit (POS); }}int sum (int x) {int sum=0; while (x>0) {sum+=c[x]; X-=lowbit (x); } return sum;} int main () {int cas=1; scanf ("%d", &TT); while (tt--) {Long long ans=0; Memset (C,0,sizeof (c)); scanf ("%d%d%d", &n,&m,&k); for (int i=1;i<=k;i++) scanf ("%d%d", &e[i].x,&e[i].y); Sort (e+1,e+1+k,cmp); for (int i=1;i<=k;i++) { Update (e[i].y,1); Ans+=i-sum (E[I].Y); } printf ("Test Case%d:%i64d\n", Cas,ans); cas++; } return 0;}
(Tree-like array) POJ 3067