严格来说应该用线段树做,不过数据量这么少,实在没有必要。如果用线段树做反而会增大空间消耗。
Accepted
|
C++
|
00:00.00
|
392K
|
#include<stdio.h>
#include <stdlib.h>
void solve(int n)
{
int i, res = 0 ;
int** data = (int**)malloc(sizeof(int*) * n);
for(i = 0; i < n; i++ )
data[i] = (int*)malloc(sizeof(int) * 2 );
for(i = 0; i < n; i++ )
{
int a, b;
scanf("%d%d", &a, & b);
a = (a - 1) / 2 ;
b = (b - 1) / 2 ;
if(a < b) data[i][0] = a, data[i][1] = b;
else data[i][0] = b, data[i][1] = a;
}
for(i = 0; i < 200; i++ )
{
int temp = 0 ;
for(int j = 0; j < n; j++ )
if(data[j][0] <= i && data[j][1] >= i) temp++ ;
if(res < temp) res = temp;
}
printf("%d/n", res * 10 );
for(i = 0; i < n; i++ ) free(data[i]);
free(data);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1029.txt", "r" , stdin);
#endif
int t, n;
while(scanf("%d", &t) != EOF)
while(t-- && scanf("%d", &n) != EOF)
solve(n);
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0 ;
}
#include <stdlib.h>
void solve(int n)
{
int i, res = 0 ;
int** data = (int**)malloc(sizeof(int*) * n);
for(i = 0; i < n; i++ )
data[i] = (int*)malloc(sizeof(int) * 2 );
for(i = 0; i < n; i++ )
{
int a, b;
scanf("%d%d", &a, & b);
a = (a - 1) / 2 ;
b = (b - 1) / 2 ;
if(a < b) data[i][0] = a, data[i][1] = b;
else data[i][0] = b, data[i][1] = a;
}
for(i = 0; i < 200; i++ )
{
int temp = 0 ;
for(int j = 0; j < n; j++ )
if(data[j][0] <= i && data[j][1] >= i) temp++ ;
if(res < temp) res = temp;
}
printf("%d/n", res * 10 );
for(i = 0; i < n; i++ ) free(data[i]);
free(data);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1029.txt", "r" , stdin);
#endif
int t, n;
while(scanf("%d", &t) != EOF)
while(t-- && scanf("%d", &n) != EOF)
solve(n);
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0 ;
}