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

蒟蒻的AC纪念

Posted by CrystalBall at 2016-10-05 00:23:14 on Problem 1003
#include <stdio.h>
#include <ctype.h>

#define elif else if
const int maxn = 276;

int Myscan(float *n)
{
	int t;
	int power = 1;
	
	*n = 0;
	
	while ((t=getchar()) != EOF && isdigit(t))
		*n = *n * 10 + t - '0';
	if (t=='.')
	{
		while ((t=getchar()) != EOF && isdigit(t))
		{
			*n = *n * 10 + t- '0';
			power *= 10;
		}
		*n /= power;
	}
	return 1;
}

int BinSearch(int low, int high, float x, float f[])
{
	int mid;	
	while (low <= high)
	{	
		mid = (low+high)>>1;
		if (x <= f[mid-1])
			high = mid-1;
		elif (x > f[mid])
			low = mid;
		if ( x > f[mid-1] && x <= f[mid])
			return mid;
		elif ( x > f[mid] && x <= f[mid+1])
			return mid+1;
	}
}
int main()
{
	float f[maxn];
	int i;
	
	f[0] = 0;
	for (i = 1; i<=maxn; i++)
		f[i] = f[i-1] + 1/(float)(i+1);
	float n;										
	while (Myscan(&n) && n != 0)
		printf("%d card(s)\n", BinSearch(1,maxn,n,f) );
	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