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

it should be dp

Posted by frkstyc at 2006-01-20 19:49:07 on Problem 2430
In Reply To:what's wrong? Posted by:PK_ILGYU at 2006-01-20 19:41:36
> #include<stdio.h>
> #include<stdlib.h>
> #define Max_n 1000
> 
> int Dap;
> 
> int N,T,M;
> 
> struct data1{
> 	int a,b;
> }Data[Max_n+1];
> 
> void init()
> {
> 	int i;
> 
> 	//FILE *fin=fopen("2430.in","r");
> 	//fscanf(fin,"%d %d %d",&N,&T,&M);
> 	scanf("%d %d %d",&N,&T,&M);
> 
> 	for(i=1; i<=N; i++){
> //		fscanf(fin,"%d %d",&Data[i].a,&Data[i].b);
> 		scanf("%d %d",&Data[i].a,&Data[i].b);
> 	}
> //	fclose(fin);
> }
> 
> int sortf(const void *a, const void *b)
> {
> 	struct data1 *p=(struct data1 *)a;
> 	struct data1 *q=(struct data1 *)b;
> 
> 	if(p->b > q->b) return 1;
> 	if(p->b < q->b) return -1;
> 	if(p->a > q->a) return 1;
> 	if(p->a < q->a) return -1;
> 	return 0;
> }
> 
> void process()
> {
> 	int i,s,e,k,sw,st,ed,mid,l,cnt;
> 
> 	s=1; e=100000000;
> 
> 	for(;;){
> 		if(s>e) break;
> 		mid=(s+e)/2;
> 		l=mid*2+2;
> 
> 		st=Data[1].b; ed=st+(l-2)/2-1; k=Data[1].a; cnt=1; sw=0;
> 		for(i=2; i<=N; i++){
> 			if(Data[i].b>ed){
> 				cnt++;
> 				if(cnt==T+1) break;
> 				st=Data[i].b; ed=st+(l-2)/2-1; k=Data[i].a; sw=0;
> 			}else if(Data[i].b==ed && sw==0){
> 				if(k!=Data[i].a){
> 					cnt++;
> 					if(cnt==T+1) break;
> 					st=Data[i].b; ed=st+(l-2)/2-1; k=Data[i].a; sw=0;
> 				}
> 			}else{
> 				if(k!=Data[i].a){
> 					if(sw==0){
> 						sw=1;
> 						ed--;
> 					}
> 				}
> 			}
> 		}
> 		if(i==N+1){
> 			Dap=l;
> 			e=mid-1;
> 		}else{
> 			s=mid+1;
> 		}
> 	}
> }
> 
> void output()
> {
> 	printf("%d",Dap);
> }
> 
> int main()
> {
> 	init();
> 	qsort(&Data[1],N,sizeof(Data[0]),sortf);
> 	process();
> 	output();
> 	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