Miss Kitty and Her Little Ice Cream Shop(水题)

Miss Kitty and Her Little Ice Cream Shop
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Download as PDF

Miss Kitty graduated from University N that has a long history of training their students to become teachers in an island country T. All of her classmates, including Miss Kitty, work very hard at school to become teachers of primary or secondary schools. However, due to the extremely low birth rate in island T, there is little demand for teachers in the island T. Miss Kitty has changed her career plan after unable to secure a stable job in the teaching market after more than 5 years of struggling. She wants to acquire other practical skills by entering graduate schools. However, the tuition for higher education in island T is very high. She needs to save money before becoming a student again. She has opened an ice cream shop near University N. She saves all of the money she earned and will close the shop and enter a graduate institute of making ice creams after she has earned at least m dollars.

She works very hard every day by selling ice creams and opens the shop every day. Nearby customers become to love her ice cream day after day. After a few days, she discovered the following magic formulas about the amount of money she earned each day. Assume x is the number of days the shop is opened. So x = 1 for the first day the shop is opened.

  • During a sunny day, her shop earns exactly a . x2 + b . x + c dollars.
  • During a cloudy day, her shop earns exactly d . x2 + e . x + f dollars.
  • During a raining day, her shop earns exactly g . x2 + h . x + i dollars.

The following is an example when a = 1 , b = 2 , c = 1 , d = 1 , e = - 2 , f = 1 , g = 0 , h = 1 and i = 1 :


x1234567
x2 + 2x + 1 (sunny)491625364964
x2 - 2x + 1 (cloudy)0149162536
x + 1 (raining)2345678


Each day is either a sunny, cloudy or raining day. Furthermore, she also discovers the following magic formulas between x and the weather.


  • If (j . x + k) can be evenly divided by 3, i.e., (j . x + k) mod 3 = 0, then it is a sunny day.
  • If (j . x + k) mod 3 = 1, then it is a cloudy day.
  • If (j . x + k) mod 3 = 2, then it is a rainy day.


Note that mod is the operator to find the reminder of integer division. The following is an example when j = 2 and k = 1 :


x1234567
2x + 13579111315
(2x + 1) mod 30210210
weathersunnyrainingcloudysunnyrainingcloudysunny


Please use the above formulas to calculate for Miss Kitty, the least integer x so that the total amount of money earned by her is at least m .

The following is an example when m = 100 using the same values for a, ... k as above:


x1234567
weathersunnyrainingcloudysunnyrainingcloudysunny
money earn today4342562564
total money earned4711364267131


Hence the answer is x = 7 . Miss Kitty needs to open the ice cream for at least 7 days.


Technical Specification

  1. 0 < m$ \le$10, 000, 000 and m is an integer
  2. -10$ \le$abcdefghijk$ \le$10 , and they are all integers

Input

The first line of the input file contains an integer indicating the number of test cases to follow. Then each of the next line contains


m a b c d e f g h i j k

Output

For each test case, output the least x so that the total amount of money earned is at least m .

Sample Input

2 
100 1 2 1 1 -2 1 0 1 1 2 1 
1234 2 1 2 2 -2 0 1 -5 0 4 8

Sample Output

7 
14

//Memory: 0 KB		Time: 12 MS
//Language: ANSI C 4.1.2		Result: Accepted

#include <stdio.h>

int main()
{
    int m, a, b, c, d, e, f, g, h, i, j, k, x, sum, T;
    scanf("%d", &T);
    while(T--)
    {
        x=1;sum=0;
        scanf("%d%d%d%d%d%d%d%d%d%d%d%d", &m, &a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k);
        while(sum < m)
        {
            int w = (j*x + k)%3;
            if(!w)
                sum += (a*x*x + b*x + c);
            else if(w == 1)
                sum += (d*x*x + e*x + f);
            else
                sum += (g*x*x + h*x + i);
            x++;
        }
        printf("%d\n", x - 1);
    }
    return 0;
}


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值