1, http://poj.org/problem?id=3067
2, the subject of the main effect:
Know that there are n,m cities on both sides of the strait, now give a connection between the two sides of the city, the line is straight, ask the two sides of the various cities of the link between the number of points of intersection
In fact, painting can be seen, just to the east coast of the cities from the big to the small sort, then for the West Bank of the city, the front than their own small will have the intersection, that is, to convert to find the point of the number of smaller than their own numbers
3, the topic Japan
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total submissions: 18985 |
|
accepted: 5143 |
The
Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads is must for the built. The Japan is Tall island with N cities on the east coast and M cities on the west Coast (M <= 1000, N <= 1000). K superhighways is build. Cities on each coast are numbered 1, 2, ... from north to South. 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 most two superhighways cross at 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 starts with three numbers–n, M, K. Each of the next K lines contains two numbers–the numbers to cities connected by the superhighway. The "the" of the "the" is the number of the the "city" of the coast and second one is the "the" of the city of the "the" of the City of coast
Output for each test case write one line on the standard output:
Test case (Case number): (Number of crossings)
Sample Input
1
3 4 4 1 4 2 3 3 2 3-
1
Sample Output
Test Case 1:5
SOURCE Southeastern Europe 2006 4, AC code:
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std;
#define N 1000005 #define LL long int n,m;
int c[n];
struct node {int x;
int y;
} a[1000005];
int CMP (node A,node b) {if (a.x==b.x) return a.y<b.y;
Return a.x<b.x;
int lowbit (int i) {return i& (-i);} void update (int x,int v) {for (int i=x;i<=m;i+=lowbit (i)) {
C[i]+=v;
an int getsum (int x) {ll sum=0;
for (int i=x;i>0;i-=lowbit (i)) {sum+=c[i];
return sum;
int main () {int t,k,cas=0;
scanf ("%d", &t);
while (t--) {cas++;
Memset (C,0,sizeof (c));
scanf ("%d%d%d", &n,&m,&k);
for (int i=1; i<=k; i++) {scanf ("%d%d", &a[i].x,&a[i].y);
Sort (a+1,a+k+1,cmp);
ll Sum=0;
for (int i=1;i<=k;i++) {update (a[i].y,1);
sum+= (Getsum (m)-getsum (A[I].Y)); printf ("Test Case%d:%lld\n", cas,sum);
return 0;
}/* 20 3 4 4 1 4 2 3 3 2 3 4 3 4 4 1 4 2 3 3 2 3 1 3 4 4 1 4 2 3 3 2 3/*
4, wrong answer code
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std;
#define N 1000005 int n,m;
int c[n];
int ans[1000005];
struct node {int x;
int y;
} a[1000005];
int CMP (node A,node b) {if (a.x==b.x) return a.y<b.y;
Return a.x>b.x;
int lowbit (int i) {return i& (-i);} void update (int x,int v) {for (int i=x;i<=m;i+=lowbit (i)) {
C[i]+=v;
an int getsum (int x) {int sum=0;
for (int i=x;i>0;i-=lowbit (i)) {sum+=c[i];
return sum;
int main () {int t,k,cas=0;
scanf ("%d", &t);
while (t--) {cas++;
Memset (C,0,sizeof (c));
scanf ("%d%d%d", &n,&m,&k);
for (int i=1; i<=k; i++) {scanf ("%d%d", &a[i].x,&a[i].y);
Sort (a+1,a+k+1,cmp);
memset (ANS) (ans,0,sizeof); for (int i=1;i<=k;i++) {if (a[i].x==a[i-1].x && a[i].y==a[i-1].y;& i>1) {ans[i]=0;
else if (a[i].x==a[i-1].x && i>1) {ans[i]=ans[i-1];
else {ans[i]=getsum (A[I].Y);
Update (a[i].y,1);
int sum=0;
for (int i=1;i<=k;i++) {//printf ("%d\n", Ans[i]);
Sum+=ans[i];
printf ("Test Case%d:%d\n", cas,sum);
return 0;
}/* 20 3 4 4 1 4 2 3 3 2 3 4 3 4 4 1 4 2 3 3 2 3 1 3 4 4 1 4 2 3 3 2 3/*