zoukankan      html  css  js  c++  java
  • 2018/12/22 acm日常 第三周 CodeForces

    A - Problem A

    问题原址

    Devu is a renowned classical singer. He is invited to many big
    functions/festivals. Recently he was invited to “All World Classical
    Singing Festival”. Other than Devu, comedian Churu was also invited.
    Devu has provided organizers a list of the songs and required time for
    singing them. He will sing n songs, ith song will take ti minutes
    exactly.

    The Comedian, Churu will crack jokes. All his jokes are of 5 minutes
    exactly.
    People have mainly come to listen Devu. But you know that he needs
    rest of 10 minutes after each song. On the other hand, Churu being a
    very active person, doesn’t need any rest.

    You as one of the organizers should make an optimal sсhedule for the
    event. For some reasons you must follow the conditions:

    The duration of the event must be no more than d minutes; Devu must
    complete all his songs; With satisfying the two previous conditions
    the number of jokes cracked by Churu should be as many as possible. If
    it is not possible to find a way to conduct all the songs of the Devu,
    output -1. Otherwise find out maximum number of jokes that Churu can
    crack in the grand event.

    Input
    The first line contains two space separated integers n, d (1 ≤ n ≤ 100; 1 ≤ d ≤ 10000). The second line contains n space-separated integers: t1, t2, …, tn (1 ≤ ti ≤ 100).

    Output
    If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
    Examples

    Input
    3 30
    2 2 1
    Output
    5
    Input
    3 20
    2 1 1
    Output
    -1

    Note(注意事项)
    Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:

    First Churu cracks a joke in 5 minutes.
    Then Devu performs the first song for 2 minutes.
    Then Churu cracks 2 jokes in 10 minutes.
    Now Devu performs second song for 2 minutes.
    Then Churu cracks 2 jokes in 10 minutes.
    Now finally Devu will perform his last song in 1 minutes.
    Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.

    Consider the second example. There is no way of organizing Devu’s all songs. Hence the answer is -1.

    problem A

    源代码

    #include<iostream>
    using namespace std;
    int main()
    {
    	int n, d, sum, x;
    	int t[105] = {0};
    	cin >> n >> d;
    	for (int i=0;i<n;i++)
    	{
    		cin >> t[i];
    		d = d - t[i];
    	}
    	sum = d - (n - 1) * 10;
    	x = 2 * (n - 1);///玩笑次数
    	if (sum<0)
    	{
    		cout << -1 << endl;
    	}
    	else
    	{
    		if (sum >= 5)
    		{
    			x += sum / 5;
    		}
    		cout << x << endl;
    	}
        return 0;
    }
    

    思想:循环输入的同时减去演奏时间,再减去休息时间(必要),看时间是否有剩。
    不够则-1。
    有多的时间看能讲多少笑话。用 / (除)计算,输出讲笑话次数(休息*2+多余)即可。

  • 相关阅读:
    docker 安装 clickhouse单机版
    CockRoachDB简介
    Ubuntu18.04 LTS Cockroach集群搭建
    ClickHouse 的一些优化参数
    ClickHouse 概念整理
    OOM Killer机制
    win10系统下载地址
    Quartz.Net在C#中的使用
    JavaScript的undefined与null、NaN的区别
    Java Web基础回顾 —JSP
  • 原文地址:https://www.cnblogs.com/gidear/p/10433316.html
Copyright © 2011-2022 走看看