facebook题

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

double get(int iC, int iB, int iP);

int main()
{
	int n;
	scanf("%d", &n);
	int *pi = (int*)malloc(n*sizeof(int));
	int ind=0;
	int n1=n;
	while(n--)
	{
		int iC,iB,iP;
		int ans=0;
		scanf("%d",&iC);
		scanf("%d",&iB);
		scanf("%d",&iP);
		pi[ind]=(int)(get(iC,iB,iP));
		ind++;
		
	}
	for(ind=0;ind<n1;ind++)
		printf("%d\n",pi[ind]);
	free(pi);
	//printf("%d\n",xx);
	getchar();
	return 0;
}

double get(int iC, int iB, int iP)
{
	double C=(double)(iC);
	double B=(double)(iB);
	double f=(double)(iP)/100.0;
	
	double x= ceil(C*f);
	if (x<C)
	{
		if(C-x>B)
		{
			x=C-B;
			return x;
		}else
		{
			return x;
		}
	}else
	{
		x=C-1;
		double i=0;
		double fd=0.0;
		for(i=0;;i++)
		{
			fd= (C-1)/C + i/(i+B);
			if(fd>=f)
				break;
		}
		x=x+i;
		return x;
	}
}

test:

3

1 1 60

2 1 60

10 2 50


2

2

8




10
70 70 70
65 50 58
51 51 60
47 47 61
50 51 69
55 61 66
42 39 63
45 46 58
55 62 60
63 68 62


49
38
31
29
35
37
27
27
33
40


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值