题目链接

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的人数,然后相加后即为所求。

代码:

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <bitset>
  4. #include <string.h>
  5. using namespace std;
  6. int A,B,C,AB,BC,AC,ABC;
  7. int a,b,c,ab,bc,ac,abc;
  8. int main()
  9. {
  10. int t,n;
  11. scanf("%d",&t);
  12. while(t--)
  13. {
  14. scanf("%d",&n);
  15. int mmax = 0;
  16. while(n--)
  17. {
  18. scanf("%d%d%d%d%d%d%d",&A,&B,&C,&AB,&BC,&AC,&ABC);
  19. abc = ABC;
  20. if(AB>=abc)
  21. ab = AB-abc;
  22. else
  23. continue;
  24. if(BC>=abc)
  25. bc = BC-abc;
  26. else continue;
  27. if(AC>=abc)
  28. ac = AC-abc;
  29. else continue;
  30. if(A >= ab+abc+ac)
  31. a = A-(ab+abc+ac);
  32. else continue;
  33. if(B >= ab+abc+bc)
  34. b = B-(ab+abc+bc);
  35. else continue;
  36. if(C >= ac+bc+abc)
  37. c = C-(ac+bc+abc);
  38. else continue;
  39. int ans = a+b+c+ab+bc+ac+abc;
  40. mmax = max(mmax,ans);
  41. }
  42. printf("%d\n",mmax);
  43. }
  44. return 0;
  45. }

2017ACM暑期多校联合训练 - Team 6 1011 HDU 6106 Classes (容斥公式)的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)

    题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...

  2. 2017ACM暑期多校联合训练 - Team 2 1011 HDU 6055 Regular polygon (数学规律)

    题目链接 **Problem Description On a two-dimensional plane, give you n integer points. Your task is to fi ...

  3. 2017ACM暑期多校联合训练 - Team 1 1011 HDU 6043 KazaQ's Socks (找规律)

    题目链接 Problem Description KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbe ...

  4. 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)

    题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...

  5. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  6. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...

  7. 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)

    题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...

  8. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

  9. 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)

    题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...

随机推荐

  1. 【Leetcode】725. Split Linked List in Parts

    Given a (singly) linked list with head node root, write a function to split the linked list into k c ...

  2. 使用JsonConfig中的setExcludes方法过滤不需要转换的属性

    Hibernate的many-to-one双向关联中,查询many方时会将one方数据顺带着查询,同时one中会有List<Many>,然后又会去查Many中的数据... 周而复始,结果j ...

  3. phpcms 发布时间 更新 时间

  4. Android 混淆签名打包

    1.混淆文件 proguard-rules.pro # Add project specific ProGuard rules here. # By default, the flags in thi ...

  5. Arrays.toString 如果传入的是对象 那么调用的是此对象的toString

    Arrays.toString(Object[] obj) 如果传入参数的是对象 那么调用的是此对象的toString

  6. Robotframework SSHLibrary库关键字

    1.连接远程机器 两种方法,一种用户名密码登录连接,一种是通过密钥连接 (1)用户名密码连接 (2)密钥连接 大概介绍下密钥:首先由用户生成一对密码,公钥与私钥:私钥是给需要连接的用户,连接时使用私钥 ...

  7. C++解析(29):类型识别

    0.目录 1.类型识别 2.动态类型识别 3.类型识别关键字 4.小结 1.类型识别 在面向对象中可能出现下面的情况: 基类指针指向子类对象 基类引用成为子类对象的别名 静态类型--变量(对象)自身的 ...

  8. [NOI2017]蚯蚓排队 hash

    题面:洛谷 题解: 我们暴力维护当前所有队伍内的所有子串(长度k = 1 ~ 50)的出现次数. 把每个子串都用一个hash值来表示,每次改变队伍形态都用双向链表维护,并暴力更新出现次数. 现在考虑复 ...

  9. NOIP2017 【游记】

    一年过去,想起去年还是个傻b[今年也是],心里总是无限的感慨. 脑海里是日日夜夜在机房的身影,一题一题AC的激情 我等今年等了许久,虽然我是个蒟蒻,但我有梦想的憧憬 鲲鹏展翅翼向天,扶摇直上九万里. ...

  10. 【期望】【P5081】Tweetuzki 爱取球

    Description Tweetuzki 有一个袋子,袋子中有 \(N\) 个无差别的球.Tweetuzki 每次随机取出一个球后放回.求取遍所有球的期望次数. 取遍是指,袋子中所有球都被取出来过至 ...