【2017多校】HDU 6106 Classes 【集合计算】

153 篇文章 0 订阅
12 篇文章 0 订阅

Classes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 698    Accepted Submission(s): 444


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
T100
1N100
0a,b,c,d,e,f,g100
 

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.
 

Source

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6106

题意:n个班每个班的学生报名ABC三种课程,求n个班中人数最多的班级。

每个班级一次给出报了A,B,C,AB,AC,BC,ABC,的人数

注:数据有可能是假的,假的数据直接忽略掉,保证一定有一个真的数据

做法:1

只报AB的人数 == 报了AB的人数 -- 报了ABC的人数

只报了A的人数 == 报了A的人数 -- 只报AB的人数 -- 只报AC的人数 -- 报了ABC的人数

这样就可以求出每个类的人数。

 AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
int a[110];
int calc()
{
    a[3]-=a[6];
    a[5]-=a[6];
    a[4]-=a[6];
    if(a[3]<0||a[5]<0||a[4]<0) return 0;
    a[0]-=a[3]+a[5]+a[6];
    a[1]-=a[3]+a[4]+a[6];
    a[2]-=a[4]+a[5]+a[6];
    if(a[0]<0||a[1]<0||a[2]<0) return 0;
    return a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6];
}
int main()
{
    int t;
    scanf("%d", &t);
    int ans = 0;
    while(t --)
    {
        int n;
        scanf("%d", &n);
        ans = 0;
        for(int i = 0; i < n; i ++)
        {
            for(int i = 0; i < 7; i ++)
                scanf("%d", &a[i]);
            ans = max(ans, calc());
        }
        printf("%d\n", ans);
    }
    return 0;
}


AC代码2:

刚开始有个问题,不能直接 判ab<=min(a,b) bc<=min(b,c) ac<min(a,c) abc<min(a,b,c)会wa,因为这个判断太松了,
所以应为ab+ac-abc<=a bc+ab-abc<=b ac+bc-abc<=c 

/**
  * 行有余力,则来刷题!
  * 博客链接:http://blog.csdn.net/hurmishine
  * 个人博客网站:http://wuyunfeng.cn/
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e1+5;
int a[7];
int getAns()
{
    //WA
    //if(a[6]>min(a[3],min(a[4],a[5])))
        //return 0;
    if(a[6]>min(a[3],min(a[4],a[5])))
        return 0;
    if(a[3]+a[5]-a[6]>a[0])
        return 0;
    if(a[3]+a[4]-a[6]>a[1])
        return 0;
    if(a[4]+a[5]-a[6]>a[2])
        return 0;
    return a[0]+a[1]+a[2]-a[3]-a[4]-a[5]+a[6];
}
int main()
{
    //freopen("C:\\Users\\hncu_acm\\Desktop\\data.txt","r",stdin);
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        int ans=0;
        while(n--)
        {
            for(int i=0;i<7;i++)
            {
                cin>>a[i];
            }
            ans=max(ans,getAns());
        }
        cout<<ans<<endl;
    }
    return 0;
}


参考博客:http://blog.csdn.net/archger/article/details/77073837


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值