您的位置:首页 > 大数据 > 人工智能

2017 Multi-University Training Contest - Team 6 Classes

2017-08-18 17:23 399 查看
http://acm.hdu.edu.cn/showproblem.php?pid=6106

题意:

  给出选A,B,C,AB,AC,BC,ABC课程的人数,来确定班级里的人数,其中有一些数据是错误的,但保证有一组数据是正确的,最后要求出数据完全正确的班级最多的人数。

思路:

  根据容斥定理,在正确的情况下,

  1.AB,AC,BC的人数应该是不小于ABC的人数;

  2.A不小于AB,AC,B不小于AB,BC,C不小于AC,BC。

  3.A不小于AB+AC−ABC,B不小于AB+BC−ABC,C不小于AC+BC−ABC。

  只要满足这所有的条件,那么这个班级的数据就肯定是正确的,最后A+B+C+ABC−AB−AC−BC即为这个班级的人数

代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
int n,T;
int a,b,c,ab,bc,ac,abc;
while(~scanf("%d",&T)){
while(T--){
scanf("%d",&n);
int ans = 0;
while(n--){
scanf("%d %d %d %d %d %d %d",&a,&b,&c,&ab,&bc,&ac,&abc);
if(a >= ab && a >= ac && b >= ab && b >= bc && c >= bc && c >= ac && ab >= abc && bc >= abc && ac >= abc && a >= (ab + ac - abc) && b >= (ab + bc - abc) && c >= (bc + ac - abc)){
int temp = a + b + c + abc - ab - bc - ac;
ans = max(ans,temp);
}
}
printf("%d\n",ans);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐