2017 Multi-University Training Contest

来源:互联网 发布:手机怎么查看淘宝积分 编辑:程序博客网 时间:2024/06/07 15:48

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+ACABC,B不小于AB+BCABC,C不小于AC+BCABC
  只要满足这所有的条件,那么这个班级的数据就肯定是正确的,最后A+B+C+ABCABACBC即为这个班级的人数

代码:

#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);        }    }}
原创粉丝点击