Codeforces Round #623 (Div. 2)

A. Fast Food Restaurant

time limit per test1 second
memory limit per test256 megabytes
nputstandard input
outputstandard output

Tired of boring office work, Denis decided to open a fast food restaurant.

On the first day he made a portions of dumplings, b portions of cranberry juice and c pancakes with condensed milk.

The peculiarity of Denis’s restaurant is the procedure of ordering food. For each visitor Denis himself chooses a set of dishes that this visitor will receive. When doing so, Denis is guided by the following rules:

every visitor should receive at least one dish (dumplings, cranberry juice, pancakes with condensed milk are all considered to be dishes);
each visitor should receive no more than one portion of dumplings, no more than one portion of cranberry juice and no more than one pancake with condensed milk;
all visitors should receive different sets of dishes.
What is the maximum number of visitors Denis can feed?

Input
The first line contains an integer t (1≤t≤500) — the number of test cases to solve.

Each of the remaining t lines contains integers a, b and c (0≤a,b,c≤10) — the number of portions of dumplings, the number of portions of cranberry juice and the number of condensed milk pancakes Denis made.

Output
For each test case print a single integer — the maximum number of visitors Denis can feed.

Example
inputCopy
7
1 2 1
0 0 0
9 1 7
2 2 3
2 3 2
3 2 2
4 4 4
outputCopy
3
0
4
5
5
5
7

Note
In the first test case of the example, Denis can feed the first visitor with dumplings, give the second a portion of cranberry juice, and give the third visitor a portion of cranberry juice and a pancake with a condensed milk.

In the second test case of the example, the restaurant Denis is not very promising: he can serve no customers.

In the third test case of the example, Denise can serve four visitors. The first guest will receive a full lunch of dumplings, a portion of cranberry juice and a pancake with condensed milk. The second visitor will get only dumplings. The third guest will receive a pancake with condensed milk, and the fourth guest will receive a pancake and a portion of dumplings. Please note that Denis hasn’t used all of the prepared products, but is unable to serve more visitors.

题目大意 :
Alan同学开了一家餐馆 每次只能给客人不同的东西 在都充足的情况下 只有七种情况 如 A B C AB AC BC ABC 其他的情况都成不可行了 按照题意进行模拟

Code

#include <iostream>
#include <algorithm>

using namespace std;
 
int main()
{
    int t; cin >> t;
    while(t --)
    {
        int a[3];
        cin >> a[0] >> a[1] >> a[2];
        
        sort(a,a+3,greater<int>());
        
        int ans = 0;
        if(a[0])
        {
            a[0] --;
            ans ++;
        }
        if(a[1])
        {
            a[1] --;
            ans ++;
        }
        if(a[2])
        {
            a[2] --;
            ans ++;
        }
        if(a[0] && a[1])
        {
            a[1] -- , a[0] --;
            ans ++;
        }
        if(a[0] && a[2])
        {
            a[0] --, a[2] --;
            ans++;
        }
        if(a[1] && a[2])
        {
            a[1] -- , a[2] --;
            ans ++;
        }
        if(a[0] && a[1] && a[2])
        {
            ans ++;
        }
        cout << ans << endl;
    }
    return 0;
}

只有三种情况 我们直接模拟就可

B. Different Rules

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output

Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the largest number of problems wins, the organizers came up with different rules.

Suppose in the first round participant A took x-th place and in the second round — y-th place. Then the total score of the participant A is sum x+y. The overall place of the participant A is the number of participants (including A) having their total score less than or equal to the total score of A. Note, that some participants may end up having a common overall place. It is also important to note, that in both the first and the second round there were no two participants tying at a common place. In other words, for every i from 1 to n exactly one participant took i-th place in first round and exactly one participant took i-th place in second round.

Right after the end of the Olympiad, Nikolay was informed that he got x-th place in first round and y-th place in the second round. Nikolay doesn’t know the results of other participants, yet he wonders what is the minimum and maximum place he can take, if we consider the most favorable and unfavorable outcome for him. Please help Nikolay to find the answer to this question.

Input
The first line contains an integer t (1≤t≤100) — the number of test cases to solve.

Each of the following t lines contains integers n, x, y (1≤n≤109, 1≤x,y≤n) — the number of participants in the olympiad, the place that Nikolay took in the first round and the place that Nikolay took in the second round.

Output
Print two integers — the minimum and maximum possible overall place Nikolay could take.

Examples
inputCopy
1
5 1 3
outputCopy
1 3
inputCopy
1
6 3 4
outputCopy
2 6

在这里插入图片描述
题目大意 :Alan 去参加比赛 一共两轮 第一次得分x,第二次得分y ,总分 x + y
问 Alan 最好和最坏的名次

解决方法 :
最差名次为 min(x + y - 1 ,n ); 不能超过n这是一定的; 我们能构造出 x + y - 1个人的成绩与 Alan 总分 x + y 相等的情况

第一次成绩  + 第二次成绩 = X + Y;
1  + x + y  - 1 = x + y;
2 + x + y - 2 = x + y;
.
.
.
.
x + y - 1  +  1  = x + y;

上述一共是 x + y - 1个人 所以最坏成绩 就是 x + y - 1;

最好名次分两种情况
(1) 如果 x + y <= n 那么我们无论如何也能构造出所有人的成绩(除去Alan)都大于等于 n + 1;

1		+		n = n + 1;
2		+		n -1 = n + 1;
.
.
.
.
n 		+		1 = n + 1;

由此可知当 x + y <= n 时 Alan 就是第一名
(2) 如果 x + y > n 那我们不妨让第一轮的第一名,第二轮也等于第一名,
那么 x 就变为 x - 1 , y 就变为 y - 1;第二轮的第二名也是如此 ····· 直到 x - t + y - t == n - t 因为我们知道当x + y == n 时 当他名次一定是第一;
由此可知 t = x + y - n ;所以有 t 个人在他前面 那么他就是 t + 1;

Code :

#include <iostream>

using namespace std;

int main()
{
    int t ; cin >> t;
    while(t --)
    {
        int n ,x ,y;
        cin >> n >> x >> y;
        
        if(x + y <= n)
            cout << 1 <<' ' << min(x + y - 1 , n) << endl;
        else
            cout << min(x + y - n + 1 , n)<<' '<< min(x + y - 1 , n) << endl;
    }
        
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值