If at first you don't succeed...(CodeForces 991A)(简单容斥)

本文通过一组学生考试后是否庆祝及选择庆祝地点的数据,提出了一个有趣的问题:如何根据已知的庆祝人数推断未通过考试的学生人数。文章还提供了一段代码来解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.

Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by AA students, BeaverKing — by BB students and CC students visited both restaurants. Vasya also knows that there are NN students in his group.

Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?

Input

The first line contains four integers — AA, BB, CC and NN (0≤A,B,C,N≤1000≤A,B,C,N≤100).

Output

If a distribution of NN students exists in which AA students visited BugDonalds, BB — BeaverKing, CC — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.

If such a distribution does not exist and Vasya made a mistake while determining the numbers AA, BB, CC or NN (as in samples 2 and 3), output −1−1.

Sample Input

Input

10 10 5 20

Output

5

Input

2 2 0 4

Output

-1

Input

2 2 2 1

Output

-1

Hint

The first sample describes following situation: 55 only visited BugDonalds, 55 students only visited BeaverKing, 55 visited both of them and 55 students (including Vasya) didn't pass the exam.

In the second sample 22 students only visited BugDonalds and 22 only visited BeaverKing, but that means all 44 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.

The third sample describes a situation where 22 students visited BugDonalds but the group has only 11 which makes it clearly impossible.

代码如下:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#include<list>
#include<algorithm>
#include <ctime>
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define memset(a,v)  memset(a,v,sizeof(a))
#define X (sqrt(5)+1)/2.0
#define maxn 320007
#define N 200005
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e-8
#define ll long long
using namespace std;



int main()
{
    int a,b,c,m;
    cin>>a>>b>>c>>m;
    if(a>m||b>m||c>m||c>a||c>b)
        cout<<"-1"<<endl;
    else if(a+b-c>=m)
        cout<<"-1"<<endl;
    else
        cout<<m-(a+b-c)<<endl;
    return 0;
}

 

<think>好的,用户的问题是关于PAM认证中account sufficient配置的作用以及quiet参数的意义,具体涉及到配置行`accountsufficient pam_succeed_if.souid =0use_uid quiet`。我需要结合提供的引用信息来回答这个问题。首先,用户提到的配置行属于PAM的account模块类型。根据引用[3],account模块用于账户验证,比如检查用户是否有权限访问服务。这里的`sufficient`表示如果该模块返回成功,则立即通过认证,不需要检查后续模块。而`required`则不同,即使失败也会继续执行后续模块,但最终结果还是失败。接下来,模块是`pam_succeed_if.so`,这个模块通常用于条件检查。参数`uid =0`可能是指检查用户ID是否为0(即root),`use_uid`可能是指使用当前用户的UID来进行检查。`quiet`参数的作用需要进一步确认,可能是不记录日志或抑制错误信息。根据引用[3],`required`模块必须成功才能通过认证,但失败结果不会立即返回。而`sufficient`如果成功则立即通过,失败则忽略。结合`quiet`参数,可能是在条件不满足时不输出信息,保持安静,避免干扰或日志污染。 需要验证`pam_succeed_if.so`的具体参数含义。例如,`uid =0`检查用户是否为root,`use_uid`可能是指使用调用者的UID而不是有效UID。`quiet`可能是在条件不满足时不记录日志或显示消息,这在引用中没有直接提到,但根据常见PAM模块的参数,quiet通常有这个作用。总结:account类型的sufficient配置在此处的作用是,如果用户是root(uid=0),则立即通过account阶段的检查,无需后续模块。quiet参数则是抑制不必要的日志或错误信息,使认证过程更安静。</think>### PAM配置中`account sufficient pam_succeed_if.so`的作用及`quiet`参数解析 #### 1. **配置行分解** ```plaintext account sufficient pam_succeed_if.so uid = 0 use_uid quiet ``` - **模块类型**:`account` 用于账户有效性检查(如权限、时间限制等),不涉及密码验证[^3]。 - **控制标记**:`sufficient` 若此模块返回成功,则**跳过后续模块**并直接通过当前阶段认证;若失败则忽略此结果,继续执行后续模块[^3]。 - **模块名**:`pam_succeed_if.so` 用于条件判断,根据参数返回成功或失败。 #### 2. **参数意义** - **`uid = 0`** 检查用户的实际用户ID(Real UID)是否为0(即root用户)。 - **`use_uid`** 指定使用调用`su`命令的用户UID(而非目标用户UID)进行判断。例如,普通用户执行`su`时,`use_uid`会检查当前用户的UID,而非切换后的root的UID。 - **`quiet`** 抑制条件不满足时的日志输出。若检查失败(如UID≠0),**不记录冗余信息**,避免日志干扰[^2]。 #### 3. **配置行为示例** - 当用户执行`su`时: - 若当前用户UID=0(如root切换自身),此模块返回成功,`sufficient`标记使account阶段**直接通过**,无需后续检查。 - 若UID≠0(如普通用户尝试`su`),此模块返回失败,但`sufficient`标记允许继续执行后续模块(如`account include system-auth`)。 #### 4. **安全隐患与调试** - 若注释此配置(如默认CentOS配置),系统会严格依赖后续模块(如`system-auth`)的账户策略。 - **`quiet`的风险**:可能掩盖权限异常信息,调试时建议暂时移除该参数以观察详细日志[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值