题目链接

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\n",mmax);
}
return 0;
}

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. Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction

    我在update数据库的时候出现的死锁 数据库表死锁 Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackExcept ...

  2. delphi 中如何执行SqlParameter形式的SQL语句

    procedure TForm1.Button1Click(Sender: TObject); begin ADOConnection1.Open('); ADOQuery1.Close; ADOQu ...

  3. SQL中的declare用法

    平时写SQL查询.存储过程都是凭着感觉来,没有探究过SQL的具体语法,一直都是按c#那一套往SQL上模仿,前几天项目中碰到一个问题引起了我对declare定义变量的作用域的兴趣. 大家都知道c#中的局 ...

  4. angular 延迟更新方法

    失去焦点后更新: <input ng-model="name" ng-model-options="{updateOn:'blur'}" />{{n ...

  5. 【Python】python操作mysql

    pymysql模块对mysql进行 import pymysql # 创建连接 conn = pymysql.connect(host=, user='root', passwd='root', db ...

  6. java 父类的引用调用自己的属性 但是调用的方法必须是重写过的父类的方法 因为编译时候把他当作父类 运行时候才是他自己 所以必须重写父类得方法

  7. BZOJ 2299 向量(裴蜀定理)

    题意:给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个向量(x ...

  8. (转)Java GC基本算法

    http://blog.csdn.net/heyutao007/article/details/38151581 1.引用计数(reference counting)    原理:此对象有一个引用,则 ...

  9. Seek the Name, Seek the Fame POJ - 2752(拓展kmp || kmp)

    题意: 就是求前缀和后缀相同的那个子串的长度  然后从小到大输出 解析: emm...网上都用kmp...我..用拓展kmp做的  这就是拓展kmp板题嘛... 求出extend数组后  把exten ...

  10. Hadoop1.2.1异常No route to host

    Hadoop1.2.1异常Bad connect ack with firstBadLink (No route to host ) 0.说明 Hadoop集群之前运行正常,增加了新节点之后,需要执行 ...