计蒜客 UCF Local Programming Contest 2015

A.Find the Twins

题目:

Dr.Orooji’s twins (Mack and Zack) play soccer. We will assume Mack wears jersey number 18 and Zack wears 17. So, Dr.O has to look for these two numbers when trying to find the twins.

The Problem:

Given a list of 10 numbers, determine if the twins are there.

The Input:

The first input line contains a positive integer, nnn, indicating the number of data sets to check. The sets are on the following nnn input lines, one set per line. Each set consists of exactly 10 single-space-separated distinct integers (each integer between 11 and 99 inclusive) giving the jersey numbers for the players.

The Output:

Print each input set. Then, on the next output line, print one of four messages (mack, zack, both, none), indicating how many of the twins are in the set. Leave a blank line after the output for each test case.

样例输入

4
11 99 88 17 19 20 12 13 33 44
11 12 13 14 15 16 66 88 19 20
20 18 55 66 77 88 17 33 44 11
12 23 34 45 56 67 78 89 91 18

样例输出

11 99 88 17 19 20 12 13 33 44
zack

11 12 13 14 15 16 66 88 19 20
none

20 18 55 66 77 88 17 33 44 11
both

12 23 34 45 56 67 78 89 91 18
mack



题意:
水题,查找数组是否有18和17,有则输出对应的名字
思路:
记录18,17判断输出即可
代码:

#include <iostream>
#include<cstring>
#include <iomanip>
#include<algorithm>
#include<cmath>
#include<array>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include <string>
using namespace std;

int main(void)
{

    int scc[15],n;
    
    string s;
    cin >> n;
    while (n--)
    {
        bool M = 0, Z = 0;
        for (int i = 0; i < 10; i++)
        {
            cin >> scc[i];
            switch(scc[i])
            {
            case 18: 
                M = 1;
                break;
            case 17:
                Z = 1;
                break;
            }
        }

        for (int i = 0; i < 10; i++)
        {
            cout << scc[i];
            if (i != 9) cout << ' ';

        }
 
        if (M == 1 && Z == 1) s = "both";
        else if (M == 1) s = "mack";
        else if (Z == 1) s = "zack";
        else s = "none";

        cout << '\n' << s<<endl;
        if (n) cout << endl;
    }
}

B. Medal Ranking

题目:
When different countries compete against each other (e.g., in the Olympics), they receive gold/silver/bronze medals. The countries can then be ranked in one of two ways: by “count” which is based on the total number of medals (regardless of the medal colors) or by “color” which is based on the number of gold medals (and silver medals if tied in gold medals, and bronze medals if tied in gold and silver).

The Problem:

Given the gold/silver/bronze medal counts for USA and Russia, you are to determine if USA wins in these two ranking methods.

The Input:

The first input line contains a positive integer, n, indicating the number of data sets to check. The sets are on the following n input lines, one set per line. Each set consists of 6 integers (each integer between 0 and 500 inclusive); the first three integers represent (respectively) the gold, silver, and bronze medal counts for USA; the last three integers provide this info for Russia (in same order).

The Output:

Print each input set. Then, on the next output line, print one of four messages (count, color, both, none), indicating how USA can win. USA will win by count if its total medal count is higher than the total for Russia. USA will win by color if it has more gold medals than Russia (if tied in gold, then USA must have more silver; if tied in gold and silver, then USA must have more bronze). Leave a blank line after the output for each test case.
样例输入

5
10 5 15 10 1 0
10 5 15 10 6 10
12 5 10 5 20 30
10 0 15 10 5 30
10 5 15 10 5 15

样例输出

10 5 15 10 1 0
both

10 5 15 10 6 10
count

12 5 10 5 20 30
color

10 0 15 10 5 30
none

10 5 15 10 5 15
none



题意:
输入两个数,前三个为美国获得的金,银,铜牌的数量,后三个为俄罗斯的,计算在数量上或者牌的颜色上,美国是否能够胜利。
思路:
模拟即可
代码:

#include <iostream>
#include<cstring>
#include <iomanip>
#include<algorithm>
#include<cmath>
#include<array>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include <string>
using namespace std;
int main(void)
{

    int scc[15],n;
    
    string s;
    cin >> n;
    while (n--)
    {
        bool cou = 0, col = 0;
        int US = 0, RU = 0;
        for (int i = 0; i < 6; i++)
        {
            cin >> scc[i];
        }
        US = scc[0] + scc[1] + scc[2];
        RU = scc[3] + scc[4] + scc[5];

        if (US > RU) cou = 1;
        
        for (int i = 0, j = 3; i < 3; i++, j++)
            if (scc[i] > scc[j]) col = 1;
            else if (scc[i]< scc[j]) break;


        for (int i = 0; i < 6; i++)
        {
            cout << scc[i];
            if (i != 5) cout << ' ';
        }
          
        if (cou == 1 && col == 1) s = "both";
        else if (cou == 1) s = "count";
        else if (col == 1) s = "color";
        else s = "none";
        cout << '\n' << s<<endl;
        if (n) cout << endl;
    }
}

C. Brownies vs. Candies vs. Cookies

题目:
Everyone is welcome to the UCF Programming Team practices, and many students take advantage of this opportunity. The main benefit is that these students improve their problem solving and programming skills. Another benefit is that the students enjoy the refreshments Dr.Orooji brings every week! Dr.O usually brings candies but sometimes he brings cookies or brownies. Brownies are very popular and don’t usually last long, so Dr.O has to come up with some clever trick to make the brownies last longer (so that the students stay for the entire practice!). Well, the easiest solution is to cut the brownies in half; that will double the number of brownies.

The Problem:

Given the original number of brownies and the students wanting brownies, you are to keep track of the brownie count as Dr.O cuts them in half.

The Input:

The first input line contains a positive integer, n, indicating the number of programming team practices. This is followed by the data for these practices. The first input line for each practice contains two integers (separated by a space): the number of students (between 1 and 30 inclusive) in the practice and the number of brownies (between 60 and 600 inclusive) Dr.O has brought that day. The next input line for the practice contains a positive integer, m, indicating how many groups of students approach the refreshment table to take brownies. This is followed by the number of students in each group, one number per line. Assume that the input values are valid, e.g., the number of students in a group will be at least 1 and it will not be greater than the number of students in the practice.

If a group of students is approaching the refreshment table and Dr.O notices that the number of remaining brownies is less than or equal to the number of students in the group, Dr.O cuts the brownies in half to be sure they won’t be all gone after each student in the group grabs one brownie. Note that, if needed, Dr.O will cut the brownies more than once (as many times as needed). For example, if there are 3 brownies left and 24 students are approaching the table, Dr.O has to cut the brownies four times (3 → 6 → 12 → 24 → 48) to be sure the brownies won’t be all gone after each student in the group grabs one.

The Output:

At the beginning of each practice, output “Practice #p: s b” where p is the practice number (starting with 1), s is the number of students in this practice, and b is the number of brownies. Then, on each of the following output lines, print the number of students in a group approaching the refreshment table and the number of brownies left after each of these students has grabbed one brownie (note that cutting in halves may occur before grabbing). Leave a blank line after the output for each practice.
样例输入

2
20 60
8
15
10
20
18
9
12
2
10
15 100
4
1
2
3
5

样例输出

Practice #1: 20 60
15 45
10 35
20 15
18 12
9 3
12 12
2 10
10 10

Practice #2: 15 100
1 99
2 97
3 94
5 89



题意:
O博士给大家分饼干,当有新的队伍完成后,如果饼干不够就不断进行二分,直到饼干数大于人数
思路:
模拟即可
代码:

#include <iostream>
#include<cstring>
#include <iomanip>
#include<algorithm>
#include<cmath>
#include<array>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include <string>
using namespace std;

int stu[10005];

int main(void)
{
    int scc[15], N, s,b,n;
    
    cin >> N;
    for (int x = 1; x <= N; x++)
    {
        cin >> s >> b >> n;
        for (int i = 0; i < n; i++) cin >> stu[i];

        printf("Practice #%d: %d %d\n", x, s, b);
        for (int i = 0; i < n; i++)
        {
            while (b <= stu[i])
                b <<=1;
            b -=stu[i];
            cout << stu[i] << ' ' << b;
            if (x != N||i!=n-1) cout << endl;
        }
        if (x != N) cout << endl;
    }   return 0;
    
}

D. Lemonade Stand

题目:
You are running a lemonade stand and have the good fortune of knowing exactly how many cups of lemonade customers are going to want to buy on each day that you run the lemonade stand. You hate to turn any customer away, so you would like to make sure that you always have enough lemons and sugar to make the appropriate number of cups of lemonade on each day. Unfortunately, the cost of lemons and sugar change daily, so you have to choose on which days you buy each, and how much of each to buy. You can buy individual lemons and five pound bags of sugar. (Note that there are 16 ounces in one pound.) On the days you choose to buy ingredients, you buy them in the morning, before any sales are made. (You’re an early riser, so you can always get to the store and back before any customers would come.) Note that you can buy as little or as much as you wish on any day to minimize your overall cost, i.e., you have enough startup money (capital) to buy as much as you wish on any day.

The Problem:

Given that you always want to have enough lemons and sugar to serve each customer, determine the minimum cost of buying those lemons and sugar.

The Input:

The first input line will have a single integer, n(1≤n≤100)n (1 \le n \le 100)n(1≤n≤100), the number of cases to process. The first line of each test case will have three space-separated positive integers: d(1≤d≤1000)d (1 \le d \le 1000)d(1≤d≤1000), the number of days you’ll run the lemonade stand, x(1≤x≤10)x (1 \le x \le 10)x(1≤x≤10), the number of lemons needed to make a single cup of lemonade, and s(1≤s≤10)s (1 \le s \le 10)s(1≤s≤10), the number of ounces of sugar needed to make a single cup of lemonade. The following d lines will contain data for days 1 through d, respectively. Each of these lines will have three integers separated by spaces: c(1≤c≤1000)c (1 \le c \le 1000)c(1≤c≤1000), the number of cups sold for that day, pl(1≤pl≤50)pl (1 \le pl \le 50)pl(1≤pl≤50), the price of a single lemon in cents for that day, and ps(1≤ps≤500)ps (1 \le ps \le 500)ps(1≤ps≤500), the price of a five pound bag of sugar in cents for that day. Note that the extra sugar and lemon from each day carry over to the next day.

The Output:

For each test case, print the minimum cost of supplies (in cents) necessary to make sure that no customer who wants a cup of lemonade gets turned away.
样例输入

2
3 3 2
200 10 399
300 8 499
400 12 499
2 5 10
9 10 199
8 20 99

样例输出

31977
1347



题意:
一直wa,没做出来,以下东华大学的题解:
你在经营一家卖柠檬水的店。制作一杯柠檬水需要消耗𝑥个柠檬和𝑠盎司糖。 柠檬是一个个卖的,糖是 5 磅每包卖的(1 磅 = 16 盎司)。 给出接下来的𝑑(𝑑 ≤ 1000)天里,每天将要卖出的柠檬水的数量,以及这一天的每个柠檬和 每包糖的价格,你可以在任意天采购任意数量的柠檬和糖,并且在一天之内是先采购柠檬和 糖再售卖柠檬水的。询问满足这𝑑天的需求的情况下,购入柠檬和糖的最少总价。
思路:
贪心。若在当天原材料够了,则不再购入。否则在当天及以前该原材料价格最低的时候购入 恰好满足当天需求的量。时间复杂度𝑂(𝑑)。
代码:

#include <iostream> 
#include <algorithm> 
#include <cstring> 
#include <cstdio> 
using namespace std; 
 
int Num[1005],A[1005],B[1005]; 
int T,Day,N,M,Ans; 
 
int main(){ 
    scanf("%d",&T); 
    while(T--){ 
        Ans=0; 
        scanf("%d%d%d",&Day,&N,&M); 
        int CountA=0,CountB=0; 
        int MinA=2147483647,MinB=2147483647; 
        for(register int i=1;i<=Day;++i){ 
            scanf("%d%d%d",&Num[i],&A[i],&B[i]); 
            MinA=min(MinA,A[i]); 
            MinB=min(MinB,B[i]); 
            if(CountA<Num[i]*N){ 
                int AddA=Num[i]*N-CountA; 
                CountA+=AddA;Ans+=AddA*MinA; 
            } 
            if(CountB<Num[i]*M){ 
                int AddB=(Num[i]*M-CountB-1)/80+1; 
                CountB+=AddB*80;Ans+=AddB*MinB; 
            } 
            CountA-=Num[i]*N; 
            CountB-=Num[i]*M; 
        } 
        printf("%d\n",Ans); 
    } 
    return 0; 
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值