# AtCoder Beginner Contest 094

## A - Cats and Dogs

Time limit : 2sec / Memory limit : 256MB

Score : 100 points

### Problem Statement

There are a total of A+B cats and dogs.Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.

Determine if it is possible that there are exactly X cats among these A+B animals.

### Constraints

• 1A100
• 1B100
• 1X200
• All values in input are integers.

### Input

Input is given from Standard Input in the following format:

A B X


### Output

If it is possible that there are exactly X cats, print YES; if it is impossible, print NO.

### Sample Input 1

Copy
3 5 4


### Sample Output 1

Copy
YES


If there are one cat and four dogs among the B=5 animals, there are X=4 cats in total.

### Sample Input 2

Copy
2 2 6


### Sample Output 2

Copy
NO


Even if all of the B=2 animals are cats, there are less than X=6 cats in total.

### Sample Input 3

Copy
5 3 2


### Sample Output 3

Copy
NO


Even if all of the B=3 animals are dogs, there are more than X=2 cats in total.

已知有A，B，X。A表示已经知道有A只Cat，A+B表示一共有A+B只Cat和Dog，问这A+B只animals中，是否有可能有X只Cat。题目很简单->但是有一个小坑，Cat最多有A+B-1条，判断的时候要注意。

    #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define DB double
#define SG string
#define LL long long
#define G(A,B) G[A][B]
#define Fp(A,B,C,D) for(A=B;A<=C;A+=D)
#define Fm(A,B,C,D) for(A=B;A>=C;A-=D)
#define Clear(A) memset(A,0,sizeof(A))
using namespace std;
const LL Max=1e3+5;
const LL Mod=1e9+7;
const LL Inf=1e18;
LL X=0;char CH=getchar();bool F=0;
while(CH>'9'||CH<'0'){if(CH=='-')F=1;CH=getchar();}
while(CH>='0'&&CH<='9'){X=(X<<1)+(X<<3)+CH-'0';CH=getchar();}
return F?-X:X;
}
inline void Write(LL X){
if(X<0)X=-X,putchar('-');
if(X>9)Write(X/10);
putchar(X%10+48);
}
int main(){
LL I,J,K;
if(C>=A&&C<=A+B-1){
puts("YES");
} else {
puts("NO");
}
return 0;
}

## B - Toll Gates

Time limit : 2sec / Memory limit : 256MB

Score : 200 points

### Problem Statement

There are N+1 squares arranged in a row, numbered 0,1,…,N from left to right.

Initially, you are in Square X.You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N.However, for each i=1,2,…,M, there is a toll gate in Square Ai, and traveling to Square Ai incurs a cost of 1.It is guaranteed that there is no toll gate in Square 0, Square X and Square N.

Find the minimum cost incurred before reaching the goal.

### Constraints

• 1N100
• 1M100
• 1XN1
• 1A1<A2<<AMN
• AiX
• All values in input are integers.

### Input

Input is given from Standard Input in the following format:

N M X
A1 A2 … AM


### Output

Print the minimum cost incurred before reaching the goal.

### Sample Input 1

Copy
5 3 3
1 2 4


### Sample Output 1

Copy
1


The optimal solution is as follows:

• First, travel from Square 3 to Square 4. Here, there is a toll gate in Square 4, so the cost of 1 is incurred.
• Then, travel from Square 4 to Square 5. This time, no cost is incurred.
• Now, we are in Square 5 and we have reached the goal.

In this case, the total cost incurred is 1.

### Sample Input 2

Copy
7 3 2
4 5 6


### Sample Output 2

Copy
0


We may be able to reach the goal at no cost.

### Sample Input 3

Copy
10 7 5
1 2 3 4 6 8 9


### Sample Output 3

Copy
3


已知N+1个空格（编号0~N），其中经过某M个空格需要花费1，你现在在X号格子，你可以到达相邻的两个格子。问你到达0号或者N号格子的最小花费值。

这道题也是一道水题，我们先将M个空格按照编号从小到大排序（防止测试数据无序），然后找X在这M个编号的位置。X左边的编号数就是需要的花费数，最后我们比较一下去最小即可。

    #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define DB double
#define SG string
#define LL long long
#define G(A,B) G[A][B]
#define Fp(A,B,C,D) for(A=B;A<=C;A+=D)
#define Fm(A,B,C,D) for(A=B;A>=C;A-=D)
#define Clear(A) memset(A,0,sizeof(A))
using namespace std;
const LL Max=1e3+5;
const LL Mod=1e9+7;
const LL Inf=1e18;
LL N,M,X,A[Max];
LL X=0;char CH=getchar();bool F=0;
while(CH>'9'||CH<'0'){if(CH=='-')F=1;CH=getchar();}
while(CH>='0'&&CH<='9'){X=(X<<1)+(X<<3)+CH-'0';CH=getchar();}
return F?-X:X;
}
inline void Write(LL X){
if(X<0)X=-X,putchar('-');
if(X>9)Write(X/10);
putchar(X%10+48);
}
int main(){
LL I,J,K;
Fp(I,1,M,1){
}sort(A+1,A+1+M);
Fp(I,1,M-1,1){
if(A[I]<X&&X<A[I+1]){
break;
}
}Write(min(I,M-I));
return 0;
}

## C - Many Medians

->感觉题目有些东西复制粘贴不过来大家可以自己翻一下。

L是一个奇数，定义某L个数中的中数是这个L个数中权值排名第（L+1）/2的数。

输入N个数（N为偶数），输出N行。对于每I行，输出这N个数中（不考虑AI）中的中数大小。

其实理解题意以后， 我们不难得到以下的做法：我们可以将这N个数记录编号后排序，然后对于每组数，查找当前忽略的数的位置，然后得到这个数的编号，比较这个数的编号与N/2的大小，如果当前忽略的数的编号>N/2的话，我们就可以输出这N个数排序后第N/2个数的值，否则，就输出这N个数排序后第N/2+1个数的值。

    #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define DB double
#define SG string
#define LL long long
#define G(A,B) G[A][B]
#define Fp(A,B,C,D) for(A=B;A<=C;A+=D)
#define Fm(A,B,C,D) for(A=B;A>=C;A-=D)
#define Clear(A) memset(A,0,sizeof(A))
using namespace std;
const LL Max=2e5+5;
const LL Mod=1e9+7;
const LL Inf=1e18;
struct Node{
LL ID,V;
}G[Max];
LL N,A[Max];
LL X=0;char CH=getchar();bool F=0;
while(CH>'9'||CH<'0'){if(CH=='-')F=1;CH=getchar();}
while(CH>='0'&&CH<='9'){X=(X<<1)+(X<<3)+CH-'0';CH=getchar();}
return F?-X:X;
}
inline void Write(LL X){
if(X<0)X=-X,putchar('-');
if(X>9)Write(X/10);
putchar(X%10+48);
}
bool Cmp(Node A,Node B){
return A.V<B.V;
}
LL Find(LL V){
LL I,J,K;
LL Left=1,Right=N;
while(Left<=Right){
LL Mid=Left+Right>>1;
if(G[Mid].V>V){
Right=Mid-1;
} else if(G[Mid].V<V){
Left=Mid+1;
} else {
return Mid;
}
}
}
int main(){
LL I,J,K;
Fp(I,1,N,1){
}sort(G+1,G+1+N,Cmp);
Fp(I,1,N,1){
LL P=Find(A[I]);
if(P>(N>>1)){
Write(G[(N>>1)].V);puts("");
} else {
Write(G[(N>>1)+1].V);puts("");
}
}
return 0;
}

## D - Binomial Coefficients

Time limit : 2sec / Memory limit : 256MB

Score : 400 points

### Problem Statement

Let comb(n,r) be the number of ways to choose r objects from among n objects, disregarding order.From n non-negative integers a1,a2,…,an, select two numbers ai>aj so that comb(ai,aj) is maximized.If there are multiple pairs that maximize the value, any of them is accepted.

### Constraints

• 2n105
• 0ai109
• a1,a2,…,an are pairwise distinct.
• All values in input are integers.

### Input

Input is given from Standard Input in the following format:

n
a1 a2 … an


### Output

Print ai and aj that you selected, with a space in between.

### Sample Input 1

Copy
5
6 9 4 2 11


### Sample Output 1

Copy
11 6


comb(ai,aj) for each possible selection is as follows:

• comb(4,2)=6
• comb(6,2)=15
• comb(6,4)=15
• comb(9,2)=36
• comb(9,4)=126
• comb(9,6)=84
• comb(11,2)=55
• comb(11,4)=330
• comb(11,6)=462
• comb(11,9)=55

Thus, we should print 11 and 6.

### Sample Input 2

Copy
2
100 0


### Sample Output 2

Copy
100 0


已知N个数，Ai，Aj为其中的某两个数。求C（Ai，Aj）的最大值（Ai>Aj）。

由组合数的定义不难得到一个小性质：如果P>Q>=M，那么C（P，M）恒大于C（Q，M）。于是我们最后的答案一定包含这个N个数的最大数。那么问题就转为了求这C（Max，Ai）的最大值。联想一下杨辉三角，可以知道其中一行的最大值是这一行最中间的数，于是我们只需要找到这N个数中最接近Max/2的数即可。

    #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define DB double
#define SG string
#define LL long long
#define G(A,B) G[A][B]
#define Fp(A,B,C,D) for(A=B;A<=C;A+=D)
#define Fm(A,B,C,D) for(A=B;A>=C;A-=D)
#define Clear(A) memset(A,0,sizeof(A))
using namespace std;
const LL Max=1e5+5;
const LL Mod=1e9+7;
const LL Inf=1e18;
LL N,Cnt=0,G[Max];
LL Ans,Tmp=Inf;
LL X=0;char CH=getchar();bool F=0;
while(CH>'9'||CH<'0'){if(CH=='-')F=1;CH=getchar();}
while(CH>='0'&&CH<='9'){X=(X<<1)+(X<<3)+CH-'0';CH=getchar();}
return F?-X:X;
}
inline void Write(LL X){
if(X<0)X=-X,putchar('-');
if(X>9)Write(X/10);
putchar(X%10+48);
}
int main(){
LL I,J,K;
Fp(I,1,N,1){
}sort(G+1,G+1+N);
Fp(I,1,N-1,1){
if(Tmp>=abs((G[N]>>1)-G[I])){
Ans=G[I];
Tmp=abs((G[N]>>1)-G[I]);
}
}cout<<G[N]<<" "<<Ans;
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：AtCoder Beginner Contest 094 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)