Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

差分数组 求重叠线段最大数

Posted by hnu201526010211 at 2016-09-14 10:20:10 on Problem 1083
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>

using namespace std;

const int MOD=(int)1e9+10;
const int maxn=4e2+11;

int a[maxn];


int main() {
   // freopen("C:\\Users\\hasee\\Desktop\\a.txt","r",stdin);
 //   freopen("C:\\Users\\hasee\\Desktop\\b.txt","w",stdout);
	int n,m,x,y;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&m);
		memset(a,0,sizeof(a));
		while(m--){
			scanf("%d%d",&x,&y);
			if(x&1) x++;if(y&1) y++;
			if(x>y) swap(x,y);
			a[x]++;a[y+1]--;
		}
		for(int i=1;i<maxn;i++) a[i]+=a[i-1];
 		printf("%d\n",*max_element(a,a+maxn)*10);
	}
    
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator