zoukankan      html  css  js  c++  java
  • Good Bye 2016 A. New Year and Hurry【贪心/做题目每道题花费时间按步长为5等差增长,求剩余时间够做几道题】

    A. New Year and Hurry
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him i minutes to solve the i-th problem.

    Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.

    How many problems can Limak solve if he wants to make it to the party?

    Input

    The only line of the input contains two integers n and k (1 ≤ n ≤ 10, 1 ≤ k ≤ 240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.

    Output

    Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.

    Examples
    input
    3 222
    output
    2
    input
    4 190
    output
    4
    input
    7 1
    output
    7
    Note

    In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3problems so the answer is 2.

    In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.

    In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7problems.

    【代码】:

    #include <bits/stdc++.h>
    
    using namespace std;
    int main()
    {
        int n,k,ans,res,cnt;
        while(cin>>n>>k)
        {
            ans=0,cnt=0;
            res=240-k;
            //cout<<"res= "<<res<<endl;//50
            for(int i=5;;i+=5)
            {
                ans+=i;
                if(ans>res||cnt>=n)
                {
                    break;
                }
                cnt++;
               // printf("cnt=%d ans=%d
    ",cnt,ans);//
            }
            cout<<cnt<<endl;
        }
        return 0;
    }
    My Code
    #include<iostream>  
    #include<cstdio>  
    #include<cmath>  
    using namespace std;  
    int main()  
    {  
        int n,k;  
        while(~scanf("%d%d",&n,&k))  
        {  
            int i,sum=k;  
            for(i=0;i<=n;i++)  
            {  
                sum+=i*5;  
                if(sum>240)  
                    break;  
            }  
            cout<<i-1<<endl;  
        }  
        return 0;  
    }  
    Others
  • 相关阅读:
    深(爆)搜专题整理
    牛客CSP-S提高组赛前集训营1 T2:乃爱与城市拥挤程度
    [BZOJ3743][Coci2015]Kamp 题解
    CSP2019-S,J初赛游记
    指针复习
    二叉树复习
    最短路复习
    数据库关联查询与模型之间的关联
    数据库操作Flask-SQLAlchemy之模型声明及数据库表的生成与删除
    csrf攻击防范
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7942164.html
Copyright © 2011-2022 走看看