Nothing is Impossible(思维题)

本文探讨了一个数学竞赛场景下的最优策略问题,n个问题各有正确与错误答案数量,m个学生通过合作选择部分问题解答以获得最高分数。文章提供了一种算法实现思路,包括将问题按答案数量排序,并采用动态分配策略来最大化得分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                          Problem D. Nothing is Impossible

                Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
                                      Total Submission(s): 3446    Accepted Submission(s): 1132

Problem Description

m students, including Kazari, will take an exam tomorrow.
The paper consists of exactly n problems, the i-th problem contains ai correct answers and bi incorrect answers, i.e. the i-th problem contains ai+bi candidates in total.
Each student should choose exactly one candidate as answer for each problem. If the answer to a certain problem is correct, then the student will get one point. The student who gets the most points wins.
Students only know the structure of the paper, but they are able to talk with each other during the exam. They decide to choose a subset S of all n problems, and they will only be able to submit answers on these problems.
They want to know the maximum size of S that the winner among them will solve all the problems in S if they take the optimal strategy.

For sample 1, students can choose S={1},and we need at least 4 students to guarantee the winner solve the only problem.
For sample 2, students can choose S={1,2,3}, and we need at least 24 students to guarantee the winner solve these three problems, but if |S|=4, we need at least 96 students, which is more than 50.

Input

The first line of the input contains an integer T (1≤T≤100) denoting the number of test cases.
Each test case starts with two integers n,m (1≤n≤100,1≤m≤109), denoting the number of problems and the number of students. Each of next n lines contains two integers ai,bi (1≤bi≤100,ai=1), indicating the number of correct answers and the number of incorrect answers of the i-th problem.

Output

For each test case, print an integer denoting the maximum size of S.

 Sample Input

2

3 5

1 3

1 3

1 3

5 50

1 1

1 3

1 2

1 3

1 5

Sample Output

1 3

题意:命题组后来改了题意,但做法基本相同。有n道题,m个学生,这m个学生串联,力求使得他们中的最高分最高(关于考试内容他们什么也不会,全靠蒙)。问你他们造出来的最高分至少能得多少分。

把答案数从小到大排列,每道题将所有人均分(这样总有做对的),下一道题再将上一道所有选项内的人均分,一直到分到某个选项的人数不足一个为止。

#include<bits/stdc++.h>
using namespace std;

//int ques[105];

struct node
{
    int s,a,b;
}ques[105];

int dp[105];

bool cmp(node a,node b)
{
    if(a.s!=b.s)
       return a.s<b.s;
    else
        return a.b<b.b;
}

int main()
{
    int num;
    scanf("%d",&num);
    while(num--)
    {
        int n,m,x,y,t;
        scanf("%d%d",&n,&m);
        t=m;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&x,&y);
            ques[i].s=x+y;
            ques[i].a=x;
            ques[i].b=y;
        }
        sort(ques,ques+n,cmp);
        memset(dp,0,sizeof(dp));
        int i=0;

        while(m/ques[i].s>0&&i<n)
        {
        //     if(m%ques[i].s>ques[i].b)
        //        m+=ques[i].s;
            m/=ques[i++].s;
        }
        printf("%d\n",i);
    }
    return 0;                                                                                                                                                                                                                                                                                                                         


}

 

<think>好的,用户让我编写一个C程序来输出特定的字符串:“nothing is impossible to a weddi”。首先,我需要确认这个字符串是否正确,特别是最后一个词“weddi”是否有拼写错误,因为常见的可能是“willing”或者“widdy”之类的,但用户明确给出了这个拼写,所以应该按照要求处理。 接下来,我需要用C语言的标准输出函数来实现。C语言中最常用的输出函数是printf(),它位于stdio.h头文件中。因此,程序的基本结构应该包括包含头文件、main函数,以及调用printf函数输出字符串。 然后,我要考虑字符串中的内容是否有特殊字符需要转义,比如引号或者反斜杠,但在这个例子中,字符串都是普通字符,不需要转义处理。所以可以直接用双引号将字符串括起来作为printf的参数。 另外,要注意main函数的正确写法。根据C标准,main函数应该返回int类型,通常写成int main(void)或者int main(int argc, char *argv[])。为了简洁,这里可以采用int main(void),并在结尾返回0表示正常退出。 然后,编写代码的大致步骤是: 1. 包含stdio.h头文件。 2. 定义main函数。 3. 使用printf输出指定的字符串,并在末尾加上换行符\n,以确保输出后光标移动到下一行。 4. 返回0。 测试一下代码是否正确,检查拼写是否正确,特别是“weddi”是否正确,以及是否遗漏了任何字符。确认无误后,就可以写出最终的代码。 最后,用户可能对C语言的基础语法或输出函数有疑问,所以需要准备相关问,比如printf的使用、main函数的格式、头文件的作用等。</think><< 要输出指定字符串,可以使用以下C语言程序: ```c #include <stdio.h> int main(void) { printf("nothing is impossible to a weddi\n"); return 0; } ``` 解释说明: 1. `#include <stdio.h>` 包含标准输入输出头文件,提供printf函数的声明 2. `int main(void)` 定义主函数,是程序执行的入口点 3. `printf()` 是格式化输出函数,直接输出双引号内的字符串字面量 4. 字符串末尾添加的`\n`是换行符,用于在输出后换行 5. `return 0` 表示程序正常退出 注意:输出内容严格按照要求保留了"weddi"的拼写形式,未做任何修改
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值