首页 > 试题广场 >

游游的you

[编程题]游游的you
  • 热度指数:691 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
游游现在有a个'y',b个'o',c个'u',他想用这些字母拼成一个字符串。
三个相邻的字母是"you"可以获得2分,两个相邻的字母是"oo",可以获得1分。
问最多可以获得多少分?

输入描述:
第一行一个整数q,代表询问次数。
接下来q行,每行三个正整数a,b,c,用空格隔开。




输出描述:
输出q行,代表每次询问的答案。
示例1

输入

3
1 1 1
2 3 2
1 5 2

输出

2
4
5

说明

第一次询问,可以拼出"you",获得2分。
第二次询问,可以拼出"oyouyou",获得4分。
第三次询问,可以拼出"uooooyou",获得5分。
#include <iostream>
#include <algorithm>

using namespace std;

int Q;
int a, b, c;
int main()
{
    cin >> Q;
    while (Q -- )
    {
        cin >> a >> b >> c;
        int t1 = min(min(a, b), c);
        int t2 = max(0, b - t1 - 1);
        cout << t1 * 2 + t2 << endl;
    }

    return 0;
}
发表于 2023-09-06 23:42:11 回复(0)
#include <iostream>
using namespace std;

int get_scores(int a, int b, int c) {
    int scores = 0;
    int you_num = min(min(a, b), c);
    int oo_num = b - you_num - 1;
    scores += 2 * you_num;
    if (oo_num > 0)
        scores += oo_num;
    return scores;
}

int main() {
    int q, a, b, c;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> a >> b >> c;
        cout <<get_scores(a, b, c) << '\n';
    }
    return 0;
}

发表于 2023-11-10 20:44:03 回复(0)
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int Q = in.nextInt();
        while (Q-- > 0) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int t1 = Math.min(Math.min(a, b), c);
            int t2 = Math.max(0, b - t1 - 1);
            System.out.println(t1 * 2 + t2);
        }
    }

发表于 2023-09-22 15:51:05 回复(0)
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int Q;
    cin >> Q;
    while (Q--) {
        int a, b, c;
        cin >> a >> b >> c;
        int t1 = min(min(a, b), c);
        int t2 = max(0, b - t1 - 1);
        cout << t1 * 2 + t2 << endl;
    }

    return 0;
}

发表于 2023-09-22 15:02:34 回复(0)
int main() {
    int q;
    cin >> q;

    long long a, b, c;  // 将变量定义在循环外部

    while (q--) {
        cin >> a >> b >> c;

        // 计算两个相邻的 "you" 组合的个数
        long long you_combinations = min(a, min(b, c));

        // 计算 "oo" 组合的个数,只有在 a - you_combinations 是偶数时才计算
        long long oo_combinations = 0;
        if ((a - you_combinations) % 2 == 0) {
            oo_combinations = min((a - you_combinations) / 2, b);
        }

        // 计算总分数
        long long total_score = you_combinations * 2 + oo_combinations;

        cout << total_score << endl;
    }

    return 0;
}

发表于 2023-09-22 14:47:36 回复(0)
import sys

num=int(input())

temp_lisrt=[]

for line in sys.stdin:
    temp_lisrt.append(list(map(int,line.split())))




def youyou(ylist):
    con=[]
    for i in ylist:
        if min(i)==0:
            con.append(i[1]-1)
        else:
            t=min(i)
            con.append(t*2+max(((i[1]-t)-1),0))

    return con

ss=youyou(temp_lisrt)
for i in ss:
    print(i)
发表于 2023-09-09 20:24:15 回复(0)