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 ...
随机推荐
- 软工网络15团队作业4——Alpha阶段敏捷冲刺-8
一.当天站立式会议照片: 二.项目进展 昨天已完成的工作: 服务器的完善,后端配置的修改. 明天计划完成的工作: 完善各个功能以及修改bug. 工作中遇到的困难: 服务器的语言编程困难,后端调试中不断 ...
- oracle impdp导入时 提示“ORA-39002: 操作无效 ORA-39070: 无法打开日志文件 ”
第一步:首先使用DBA权限的用户创建directory,我使用system ,可以在服务器本地创建,也可以远程连接sqlplus进行创建,使用的将是服务器上面的路径.要确保创建directory时,操 ...
- 出现脚本错误或者未正确调用 Page()
pages/xxxx/xxxx.js 出现脚本错误或者未正确调用 Page() 自己创建的小程序出现上面报错,可能是因为 xxxx.js是一个空文件,所以才会出现未正确调用: 如果是空文件的话,解决办 ...
- 【bzoj5146】有趣的概率 微积分
题目描述 "可爱的妹子就像有理数一样多,但是我们知道的,你在数轴上随便取一个点取到有理数的概率总是0,"芽衣在床上自顾自的说着这句充满哲理的话,"诶,柚子,我写完概率论的 ...
- 【一】shiro入门 之 Shiro简介
Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在JavaSE 环境,也可以用在JavaEE 环境.Shiro 可以帮助我们完成:认证.授权.加密.会话管理.与Web 集成.缓存等.这不就是 ...
- BZOJ3747 POI2015Kinoman(线段树)
考虑固定左端点,求出该情况下能获得的最大值.于是每次可以在某数第一次出现的位置加上其价值,第二次出现的位置减掉其价值,查询前缀最大值就可以了.每次移动左端点在线段树上更新即可. #include< ...
- "XX cannot be resolved to a type "eclipse报错及解决
好久都没有写博了,还记得自己准备考研,结果你会发现——你永远不知道,你将会走上哪个路. 长远的目标是好的,但有些时候身不由己也迫不得已!做好自己的当下就是好的. 不论搞什么,总会遇到各种各样的问题,以 ...
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
一.前言 实际项目开发过程中会用到多个环境,比如dev,test,product环境,不同的环境可能使用不同参数,为便于部署提高效率,本篇主要通过properties配置文件来实现多环境的配置. 二. ...
- Java进程配置文件Reload
我们在开发Java程序的时候,很多常量信息都存在配置文件中,比如数据库连接信息.ip黑名单,事件的超时时间等等.当需要该这些配置的值时都需要重新启动进程,改动的配置才会生效,有时候线上的应用不能容忍这 ...
- 【JQuery】效果
一.前言 接着上一章事件,继续jQuery的学习. 二.内容 animate 执行css属性集的自定义动画 $(selector).animate(styles,speed,easing ...