zoukankan      html  css  js  c++  java
  • 2017ACM暑期多校联合训练

    题目链接

    Problem Description
    The school set up three elective courses, assuming that these courses are A, B, C. N classes of students enrolled in these courses.
    Now the school wants to count the number of students who enrolled in at least one course in each class and records the maximum number of students.
    Each class uploaded 7 data, the number of students enrolled in course A in the class, the number of students enrolled in course B, the number of students enrolled in course C, the number of students enrolled in course AB, the number of students enrolled in course BC, the number of students enrolled in course AC, the number of students enrolled in course ABC. The school can calculate the number of students in this class based on these 7 data.
    However, due to statistical errors, some data are wrong and these data should be ignored.
    Smart you must know how to write a program to find the maximum number of students.

    Input
    The first line of the input gives the number of test cases T; T test cases follow.
    Each case begins with one line with one integer N, indicates the number of class.
    Then N lines follow, each line contains 7 data: a, b, c, d, e, f, g, indicates the number of students enrolled in A, B, C, AB, BC, AC, ABC in this class.
    It's guaranteed that at least one data is right in each test case.

    Limits
    T≤100
    1≤N≤100
    0≤a,b,c,d,e,f,g≤100

    Output
    For each test case output one line contains one integer denotes the max number of students who enrolled in at least one course among N classes.

    Sample Input
    2
    2
    4 5 4 4 3 2 2
    5 3 1 2 0 0 0
    2
    0 4 10 2 3 4 9
    6 12 6 3 5 3 2

    Sample Output
    7
    15

    Hint
    In the second test case, the data uploaded by Class 1 is wrong.
    Because we can't find a solution which satisfies the limitation.
    As for Class 2, we can calculate the number of students who only enrolled in course A is 2,
    the number of students who only enrolled in course B is 6, and nobody enrolled in course C,
    the number of students who only enrolled in courses A and B is 1,
    the number of students who only enrolled in courses B and C is 3,
    the number of students who only enrolled in courses A and C is 1,
    the number of students who enrolled in all courses is 2,
    so the total number in Class 2 is 2 + 6 + 0 + 1 + 3 + 1 + 2 = 15.

    题意:

    有A、B、C三门课程,A表示只选课程A的人数,B表示只选课程B的人数,C表示只选课程C的人数,AB表示既选课程A又选课程B的人数,BC表示既选课程B又选课程C的人数,AC表示既选课程A又选课程C的人数,ABC表示既选课程A又选课程B又选课程C的人数,求出一共用多少学生参与选课。

    分析:

    因为数据中可能存在输入错误的,所以我们要先判断输入的数据是否正确,如果错误的话就不考虑这组数据。

    判断数据正误的时候,计算出来每一部分单独表示的含义,a、b、c、ab、bc、ac、abc表示的分别是只选了课程A、B、C、AB、BC、AC、ABC的人数,然后相加后即为所求。

    代码:

    #include <iostream>
    #include <stdio.h>
    #include <bitset>
    #include <string.h>
    
    using namespace std;
    
    int A,B,C,AB,BC,AC,ABC;
    int a,b,c,ab,bc,ac,abc;
    int main()
    {
        int t,n;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            int mmax = 0;
            while(n--)
            {
                scanf("%d%d%d%d%d%d%d",&A,&B,&C,&AB,&BC,&AC,&ABC);
                abc = ABC;
                if(AB>=abc)
                    ab = AB-abc;
                else
                    continue;
                if(BC>=abc)
                    bc = BC-abc;
                else continue;
                if(AC>=abc)
                    ac = AC-abc;
                else continue;
                if(A >= ab+abc+ac)
                    a = A-(ab+abc+ac);
                else continue;
                if(B >= ab+abc+bc)
                    b = B-(ab+abc+bc);
                else continue;
                if(C >= ac+bc+abc)
                    c = C-(ac+bc+abc);
                else continue;
                int ans = a+b+c+ab+bc+ac+abc;
                mmax = max(mmax,ans);
            }
            printf("%d
    ",mmax);
        }
        return 0;
    }
    
  • 相关阅读:
    C#3.0分部份方法
    欢迎提议
    控制台关闭的特殊处理
    好头晕
    c#如何计算当月季度时间段
    CMMI定义(转)
    SQL Server 聚集索引和非聚集索引的区别
    ObjectBuilder2.0 的学习
    WaitHandle、AutoResetEvent、ManualResetEvent整理
    使用XML RPC进行远程调用
  • 原文地址:https://www.cnblogs.com/cmmdc/p/7341093.html
Copyright © 2011-2022 走看看