zoukankan      html  css  js  c++  java
  • 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 :


    x 1 2 3 4 5 6 7
    x2 + 2x + 1 (sunny) 4 9 16 25 36 49 64
    x2 - 2x + 1 (cloudy) 0 1 4 9 16 25 36
    x + 1 (raining) 2 3 4 5 6 7 8


    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 :


    x 1 2 3 4 5 6 7
    2x + 1 3 5 7 9 11 13 15
    (2x + 1) mod 3 0 2 1 0 2 1 0
    weather sunny raining cloudy sunny raining cloudy sunny


    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:


    x 1 2 3 4 5 6 7
    weather sunny raining cloudy sunny raining cloudy sunny
    money earn today 4 3 4 25 6 25 64
    total money earned 4 7 11 36 42 67 131


    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;
    }


  • 相关阅读:
    指针
    基本数据类型和string类型的转换
    golang的数据类型之基本数据类型的默认值和转换
    golang的数据类型之字符串类型
    golang的数据类型之布尔类型
    windows pyspider WEB显示框太小解决方法
    MYSQL的全局变量和会话变量
    php 日期计算 总结
    使用 PHPMailer 发送邮件
    MySQL两种表存储结构MyISAM和InnoDB的性能比较测试
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910578.html
Copyright © 2011-2022 走看看