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

Re:这题二分过了的请试试这个数据,,至少网上二分的代码没人能过

Posted by 2333hhh at 2018-09-18 13:30:48 on Problem 2010
In Reply To:Re:这题二分过了的请试试这个数据,,至少网上二分的代码没人能过 Posted by:2333hhh at 2018-09-18 13:30:23
#include<iostream>
#include<cstdio>
#include<cmath> 
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set> 
using namespace std;
typedef long long ll;

int N,C,F;

struct node
{
	int score,aid,rk;
};

node cow[100000+5];

bool cmp1(node a,node b)
{
	return a.score<b.score;
}

bool cmp2(node a,node b)
{
	return a.aid<b.aid;
}
 void show(int i)
{
	printf("score:%d aid:%d rk:%d  ",cow[i].score,cow[i].aid,cow[i].rk);
}

void show2()
{
	int i;
	for(i=0;i<C;i++)
	{
		show(i);
		printf("\n");
	}
}

int bina(int p)
{ 
    //printf("pivet:");show(p);printf("\n");
	int i;
	int l=0,r=0;
	int nd=N/2;
	int money=cow[p].aid;
	for(i=0;i<C;i++)
	{
		if(cow[i].rk>cow[p].rk&&r<nd&&money+cow[i].aid<=F)
		{
		   // printf("GRETER:");show(i);
			r++;
			money+=cow[i].aid;
		}
		else if(cow[i].rk<cow[p].rk&&l<nd&&money+cow[i].aid<=F)
		{
		//	printf("LESS:");show(i);
			l++;
			money+=cow[i].aid;
		}
	}
	 //printf("\n");
	if(l==nd&&r==nd)return 1;
	else if(l<nd)return 2;
	else return 3;
}

int main()
{  
   scanf("%d%d%d",&N,&C,&F);
   int i;
   for(i=0;i<C;i++)	scanf("%d%d",&cow[i].score,&cow[i].aid);
   sort(cow,cow+C,cmp2);
   
   int s=0;
   for(i=0;i<N;i++)s+=cow[i].aid;
   if(s>F)
   {
   	printf("-1");
   	return 0;
   }
   
   s-=cow[N-1].aid;
   for(i=C-1;i>=0;i--)
   {
   	if(cow[i].aid+s>F) C--;
   }
   
   
   sort(cow,cow+C,cmp1);
   int ans=cow[0].score;
   for(i=0;i<C;i++)cow[i].rk=i;
   sort(cow,cow+C,cmp2);
   //show2();
   
   int l=0;
   int r=C-1;
   int mid;
   while(l<=r)
   {
   	mid=(l+r)>>1;
   	for(i=0;i<C;i++)
   	if(cow[i].rk==mid)
   	{
   		break;
   	}
   	int t=bina(i);
   	
   	if(t==1)
   	{
   		if(ans<cow[i].score)ans=cow[i].score;
   		l=mid+1;
   	}
   	else if(t==2)
   	{
   		l=mid+1;
   	}
   	else 
   	{
   		r=mid-1;
   	}
   }
   printf("%d",ans);
   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