zoukankan      html  css  js  c++  java
  • HDU

    The Third Cup is Free

    Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1811    Accepted Submission(s): 846


    Problem Description
    Panda and his friends were hiking in the forest. They came across a coffee bar inside a giant tree trunk.
    Panda decided to treat everyone a cup of coffee and have some rest. Mr. Buck, the bartender greeted Panda and his animal friends with his antler. He proudly told them that his coffee is the best in the forest and this bar is a Michelin-starred bar, thats why the bar is called Starred Bucks.
    There was a campaign running at the coffee bar: for every 3 cups of coffee, the cheapest one is FREE. After asking all his friends for their flavors, Panda wondered how much he need to pay.
     

    Input
    The first line of the input gives the number of test cases, T.
    T test cases follow. Each test case consists of two lines. The first line contains one integer N, the number of cups to be bought.
    The second line contains N integers p1,p2,,pN representing the prices of each cup of coffee.
     

    Output
    For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the least amount of money Panda need to pay.

    limits


    1 ≤ T ≤ 100.
    1 ≤ N ≤ 105.
    1 ≤ pi ≤ 1000.

     


    Sample Input
    2 3 1 2 3 5 10 20 30 20 20
     

    Sample Output
    Case #1: 5 Case #2: 80


    题意:三杯中价格最低的一杯免费。

    思路:直接按价格从大到小排序,三个一循环。

    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    
    bool cmp(int a, int b)
    {
    	return a > b;
    }
    int main()
    {
    	int T, N;
    	int pi[100005];
    	scanf("%d", &T);
    	int n = 0;
    	while (T--)
    	{
    		n++;
    		int sum = 0;
    		scanf("%d", &N);
    		for (int i = 0; i < N; i++)
    		{
    			scanf("%d", &pi[i]);
    		}
    		sort(pi, pi + N,cmp);
    		for (int i = 0; i < N; i++)
    		{
    			if ((i + 1) % 3 != 0)
    			{
    				sum+=pi[i];
    			}
    		}
    		printf("Case #%d: %d
    ", n, sum);
    	}
    	return 0;
    }


  • 相关阅读:
    怎样设置HTML上传控件,上传文件的大小
    在winform里怎么调用WebBrowser控件里的脚本
    可输入的DropDownList控件
    javascript + DIV +CSS 实现可拖动消息窗体
    又是一周的开始
    document.execCommand() 解析
    怎样将DataGrid的列值统计并显示在页脚
    如何添加在线QQ咨询?
    徐普~~~~个性语言堪称经典~~~~
    软键盘的实现
  • 原文地址:https://www.cnblogs.com/csu-lmw/p/9124475.html
Copyright © 2011-2022 走看看