2017ACM暑期多校联合训练 - Team 6 1011 HDU 6106 Classes (容斥公式)
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 (容斥公式)的更多相关文章
- 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)
题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...
- 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)
题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...
随机推荐
- CNN误差反传时旋转卷积核的简明分析(转)
CNN(卷积神经网络)的误差反传(error back propagation)中有一个非常关键的的步骤就是将某个卷积(Convolve)层的误差传到前一层的池化(Pool)层上,因为在CNN中是2D ...
- PAT 甲级 1083 List Grades
https://pintia.cn/problem-sets/994805342720868352/problems/994805383929905152 Given a list of N stud ...
- PAT 甲级 1081 Rational Sum (数据不严谨 点名批评)
https://pintia.cn/problem-sets/994805342720868352/problems/994805386161274880 Given N rational numbe ...
- cli 中php的配置和phpinfo不一样
这是因为加载的php.ini的路径不一样 可以通过查看 php -i | grep php.ini 来确定两个加载的配置路径是一样的 win中没有grep的命令,可以把php -i 的内容重定向输出到 ...
- 第88天:HTML5中使用classList操作css类
在HTML5 API里,页面DOM里的每个节点上都有一个classList对象,程序员可以使用里面的方法新增.删除.修改节点上的CSS类.使用classList,程序员还可以用它来判断某个节点是否被赋 ...
- caffe框架下目标检测——faster-rcnn实战篇问题集锦
1.问题 解决方案:没编译好,需要在lib下编译make 需要在caffe-fast-rcnn下编译make或者make all -j16 ,还需要make pycaffe 2.问题 解决方案:/p ...
- 【数据库_Postgresql】数据库主键自增长之加序列和不加序列2种方法
将表的主键进行序列增加之后可以在数据库层面自动主键id增长 方法如下:先建序列,然后建表关联id主键,然后添加语句,不用考虑id主键 DROP SEQUENCE IF EXISTS "pub ...
- Lyft Level 5 Challenge 2018 - Elimination Round翻车记
打猝死场感觉非常作死. A:判一下起点和终点是否在其两侧即可. #include<iostream> #include<cstdio> #include<cmath> ...
- 具体数学斯特林数-----致敬Kunth
注意这里讲的是斯特林数而非斯特林公式. 斯特林数分两类:第一类斯特林数 和 第二类斯特林数. 分别记为. 首先描述第二类斯特林数. 描述为:将一个有n件物品的集合划分成k个非空子集的方法数. 比如集合 ...
- Mybatis笔记一:java.lang.NoClassDefFoundError: org/apache/ibatis/mapping/DatabaseIdProvider
异常错误:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSess ...