| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
枚举 + 线段的并 (扫描线) 250ms#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#define mod 10e9+7;
#define inf 0x3f3f3f3f;
#define mem0(x , y) memset(x , y , sizeof(x))
using namespace std;
const int MAX = 10100 ;
int line[MAX*10][2] ;
int sml[MAX] ;
int main(){
///freopen("input" , "r" , stdin) ;
int n , p;
int ans = 0 ;
while(scanf("%d%d",&n,&p) !=EOF){
ans = 0x3f3f3f3f ;
for(int i=0;i<p;i++){
scanf("%d%d",&line[i][0],&line[i][1]) ;
if(line[i][0] > line[i][1]) swap(line[i][0] , line[i][1]) ;
}
for(int i=1;i<=n;i++){
int sum = 0 , tot = 0;
mem0(sml , 0) ;
for(int j=0;j<p;j++){
if(line[j][0] >= i || line[j][1] < i) {
sml[line[j][0]] ++ ;
sml[line[j][1]] -- ;
}
else {
sml[line[j][0]] -- ;
sml[line[j][1]] ++ ;
}
}
tot += sml[i] ;
for(int j=i%n+1;j!=i;j=(j%n)+1){
if(tot > 0) sum ++ ;
tot += sml[j] ;
}
ans = min(ans , sum) ;
}
printf("%d\n",ans) ;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator