codeforces day 4

problem tags:greedy,brute force

题目:

C. Boats Competition

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are 𝑛n people who want to participate in a boat competition. The weight of the 𝑖i-th participant is 𝑤𝑖wi. Only teams consisting of twopeople can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight.

So, if there are 𝑘k teams (𝑎1,𝑏1)(a1,b1), (𝑎2,𝑏2)(a2,b2), ……, (𝑎𝑘,𝑏𝑘)(ak,bk), where 𝑎𝑖ai is the weight of the first participant of the 𝑖i-th team and 𝑏𝑖bi is the weight of the second participant of the 𝑖i-th team, then the condition 𝑎1+𝑏1=𝑎2+𝑏2=⋯=𝑎𝑘+𝑏𝑘=𝑠a1+b1=a2+b2=⋯=ak+bk=s, where 𝑠s is the total weight of each team, should be satisfied.

Your task is to choose such 𝑠s that the number of teams people can create is the maximum possible. Note that each participant can be in no more than one team.

You have to answer 𝑡t independent test cases.

Input

The first line of the input contains one integer 𝑡t (1≤𝑡≤10001≤t≤1000) — the number of test cases. Then 𝑡t test cases follow.

The first line of the test case contains one integer 𝑛n (1≤𝑛≤501≤n≤50) — the number of participants. The second line of the test case contains 𝑛n integers 𝑤1,𝑤2,…,𝑤𝑛w1,w2,…,wn (1≤𝑤𝑖≤𝑛1≤wi≤n), where 𝑤𝑖wi is the weight of the 𝑖i-th participant.

Output

For each test case, print one integer 𝑘k: the maximum number of teams people can compose with the total weight 𝑠s, if you choose 𝑠soptimally.

解析:题意n个人,n个体重,两个一组,每组的体重都要一样,问这n个人最多能够有多少个组,因为数据很小直接暴力就完事

#include <iostream>
using   namespace std;
int w[52],a[52];
int main(int argc, const char * argv[]) {
    // insert code here...、
    int t;
    cin>>t;
    while (t--)//题意n个人,n个体重,两个一组,每组的体重都要一样,问这n个人最多能够有多少个组
    {
        int n,Max=0;
        cin>>n;
        for (int i=1; i<=n; i++) {
            cin>>w[i];
        }
        for (int k=2; k<=100; k++)
        {
            memset(a, 0, sizeof a);//将数组a全部初始化成0,
 
            int num=0;
            for (int i=1; i<=n; i++)
            {
                for (int j=1; j<=n; j++)
                {
                    if (j!=i&&k==w[j]+w[i]&&!a[j]&&!a[i])
                    {
                        a[j]=1;
                        a[i]=1;
                        num++;
                    }
                }
            }
            if (num>Max)
            {
                Max=num;
            }
        }
        cout<<Max<<endl;
    }
    return 0;
}

内容概要:该题库专为研究生入学考试计算机组成原理科目设计,涵盖名校考研真题、经典教材课后习题、章节题库和模拟试题四大核心模块。名校考研真题精选多所知名高校的计算机组成原理科目及计算机联考真题,并提供详尽解析,帮助考生把握考研命题趋势与难度。经典教材课后习题包括白中英《计算机组成原理》(第5版)和唐朔飞《计算机组成原理》(第2版)的全部课后习题解答,这两部教材被众多名校列为考研指定参考书目。章节题库精选代表性考题,注重基础知识与重难点内容,帮助考生全面掌握考试大纲要求的知识点。模拟试题依据历年考研真题命题规律和热门考点,精心编制两套全真模拟试题,并附标准答案,帮助考生检验学习成果,评估应试能力。 适用人群:计划参加研究生入学考试并报考计算机组成原理科目的考生,尤其是需要系统复习和强化训练的学生。 使用场景及目标:①通过研读名校考研真题,考生可以准确把握考研命题趋势与难度,有效评估复习成效;②通过经典教材课后习题的练习,考生可以巩固基础知识,掌握解题技巧;③通过章节题库的系统练习,考生可以全面掌握考试大纲要求的各个知识点,为备考打下坚实基础;④通过模拟试题的测试,考生可以检验学习成果,评估应试能力,为正式考试做好充分准备。 其他说明:该题库不仅提供详细的题目解析,还涵盖了计算机组成原理的各个方面,包括计算机系统概述、数据表示与运算、存储器分层、指令系统、中央处理器、总线系统和输入输出系统等。考生在使用过程中应结合理论学习与实践操作,注重理解与应用,以提高应试能力和专业知识水平。
### Codeforces Div4 比赛难度等级 Codeforces的比赛通常按照不同的分组来划分参赛者,而Div.4是专门为较低评级的选手设计的比赛。这类比赛允许rating在1400或更低的参与者加入[^1]。 对于题目难度分布,在一场典型的Codeforces比赛中,会有一系列按字母顺序排列的任务,从最简单的A类问题到更复杂的后续任务(如B、C等)。每道题目的预期解决难度随着字母表位置增加而上升。然而具体针对Div.4赛事而言: - **简单入门级挑战**:像A和B这样的早期问题是相对容易处理的,旨在测试基本概念理解和编程技能的基础应用。 - **中级复杂度**:接下来的问题比如C和D则需要更多的算法知识以及解决问题的能力,尽管仍然保持在一个较为基础的水平上以便适合新接触竞赛编程的人群参与进来并获得成长的机会。 - **高级但可控**:最后几道题E及以上可能会涉及到更加深入的数据结构或是优化技巧等内容;不过即便如此,在Div.4里这些难题也会被调整得让目标群体能够触及,鼓励大家不断进步的同时不至于感到过分挫败。 值得注意的是,虽然上述描述提供了一个大致框架用于理解Div.4比赛内各层次试题的大致定位,但是每次具体的赛事设置仍取决于命题团队的选择,并且实际难易程度也可能因个人背景差异有所不同。 ```python # 示例代码展示如何判断一个问题属于哪个难度范围 def determine_problem_difficulty(rating): if rating <= 800: return "Very Easy" elif 800 < rating <= 1200: return "Easy" elif 1200 < rating <= 1600: return "Medium" elif 1600 < rating <= 2000: return "Hard" else: return "Very Hard" print(determine_problem_difficulty(750)) # 输出 Very Easy ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值