zoj 2345

94 篇文章 0 订阅
//2593430 	2011-07-23 16:04:25 	Accepted 	        2345 	C 	0 	160 	ylwh!
//2593426 	2011-07-23 16:01:54 	Presentation Error 	2345 	C 	0 	160 	ylwh!
#include <stdio.h>
int days[143]={0,1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,136,153,171,190,210,231,253,276,300,
                325,351,378,406,435,465,496,528,561,595,630,666,703,741,780,820,861,903,946,990,
                1035,1081,1128,1176,1225,1275,1326,1378,1431,1485,1540,1596,1653,1711,1770,1830,
                1891,1953,2016,2080,2145,2211,2278,2346,2415,2485,2556,2628,2701,2775,2850,2926,
                3003,3081,3160,3240,3321,3403,3486,3570,3655,3741,3828,3916,4005,4095,4186,4278,
                4371,4465,4560,4656,4753,4851,4950,5050,5151,5253,5356,5460,5565,5671,5778,5886,
                5995,6105,6216,6328,6441,6555,6670,6786,6903,7021,7140,7260,7381,7503,7626,7750,
                7875,8001,8128,8256,8385,8515,8646,8778,8911,9045,9180,9316,9453,9591,9730,9870,
                10011};
int money[143]={0, 1,5,14,30,55,91,140,204,285,385,
                506,650,819,1015,1240,1496,1785,2109,2470,2870,
                3311,3795,4324,4900,5525,6201,6930,7714,8555,9455,
                10416,11440,12529,13685,14910,16206,17575,19019,20540,22140,
                23821,25585,27434,29370,31395,33511,35720,38024,40425,42925,
                45526,48230,51039,53955,56980,60116,63365,66729,70210,73810,
                77531,81375,85344,89440,93665,98021,102510,107134,111895,116795,
                121836,127020,132349,137825,143450,149226,155155,161239,167480,173880,
                180441,187165,194054,201110,208335,215731,223300,231044,238965,247065,
                255346,263810,272459,281295,290320,299536,308945,318549,328350,338350,
                348551,358955,369564,380380,391405,402641,414090,425754,437635,449735,
                462056,474600,487369,500365,513590,527046,540735,554659,568820,583220,
                597861,612745,627874,643250,658875,674751,690880,707264,723905,740805,
                757966,775390,793079,811035,829260,847756,866525,885569,904890,924490,
                944371};



int Binsearch(int x)
{
	int begin = 0,end = 142;
	while( begin <= end )
	{
		int mid = ( begin + end )/2;
		if( x >= days[mid] && x < days[mid+1] )	return mid;
		else if(x == days[mid+1]) return mid+1;
		if( x > days[mid] )
			begin = mid + 1;
		else
			end = mid - 1;
	}
	return -1;
}
int main()
{
    
    int block, day, num, total;
    scanf("%d", &block);
    while(block--)
    {
        while(scanf("%d", &day) && day!=0)
        {
            num = Binsearch( day );
            total = money[ num ] + (day - days[num] ) * (num + 1);
            printf("%d %d\n", day, total);
        }   
        if(block)printf("\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值