AtCoder Yahoo Programming Contest 2019
第一次打AtCoer的比赛,网络卡到爆炸,页面都打不开……体验极差(所以题目也不想补了
A - Anti-Adjacency
Description:
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1 .
Input:
Input is given from Standard Input in the following format:
N K
- 1≤N,K≤100
- N and K are integers.
Output
If we can choose K integers as above, print YES
; otherwise, print NO
.
Sample Input:
3 2
Sample Output:
YES
Sample Input:
5 5
Sample Output:
NO
Sample Input:
31 10
Sample Output:
YES
Sample Input:
10 90
Sample Output:
NO
题目链接
问在 [1,n] 内能否拿出不连续的 k 个数
[1,n] 内最多可取的不连续数字数量为 ⌈2n⌉ ,所以直接和 k 比较判断即可
AC代码:
#include <bits/stdc++.h>
using namespace std;
int N, K;
int main(int argc, char *argv[]) {
scanf("%d%d", &N, &K);
if (N >= 2 * K - 1) printf("YES\n");
else printf("NO\n");
return 0;
}
B - Path
Description:
There are four towns, numbered 1,2,3 and 4 . Also, there are three roads. The ii-th road connects different towns ai and bi bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.
Determine if we can visit all the towns by traversing each of the roads exactly once.
Input:
Input is given from Standard Input in the following format:
a1 b1
a2 b2
a3 b3
- 1≤ai,bi≤4(1≤i≤3)
- ai and bi are different. (1≤i≤3)
- No two roads connect the same pair of towns.
- Any town can be reached from any other town using the roads.
Output:
If we can visit all the towns by traversing each of the roads exactly once, print YES
; otherwise, print NO
.
Sample Input:
4 2
1 3
2 3
Sample Output:
YES
Sample Input:
3 2
2 4
1 2
Sample Output:
NO
Sample Input:
2 1
3 2
4 3
Sample Output:
YES
题目链接
判断四个顶点的图是否为欧拉图或半欧拉图
欧拉图所有顶点均为偶度,半欧拉图有且仅有两个顶点为奇度,直接判定即可
AC代码:
#include <bits/stdc++.h>
using namespace std;
int Deg[5];
set<int> Flag;
int Cnt;
int main(int argc, char *argv[]) {
for (int i = 1; i <= 4; ++i) Flag.insert(i);
for (int i = 0, A, B; i < 3; ++i) {
scanf("%d%d", &A, &B);
Deg[A]++; Deg[B]++;
Flag.erase(A); Flag.erase(B);
}
if (!Flag.empty()) {
printf("NO\n");
return 0;
}
for (int i = 1; i <= 4; ++i) {
if (Deg[i] & 1) {
Cnt++;
}
}
if (Cnt != 2) printf("NO\n");
else printf("YES\n");
return 0;
}
C - When I hit my pocket…
Description:
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
- Hit his pocket, which magically increases the number of biscuits by one.
- Exchange A biscuits to 1 yen.
- Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke’s pocket after K operations.
Input:
Input is given from Standard Input in the following format:
K A B
- 1≤K,A,B≤109
- K,A and B are integers.
Output:
Print the maximum possible number of biscuits in Snuke’s pocket after K operations.
Sample Input:
4 2 6
Sample Output:
7
Sample Input:
7 3 4
Sample Output:
8
Sample Input:
314159265 35897932 384626433
Sample Output:
48518828981938099
题目链接
Snuke 一开始有 1 块饼干和 0 元钱,每次操作他可以加一块饼干或用 A 块饼干换 1 元钱或用 1 元钱换 B 块饼干,求 K 次操作后的饼干数量最大值
Snuke 每次用 A 块饼干换到 B 块需要进行 2 次操作,所以当 A≥B−1 时没有直接增加一块饼干更优否则就每两次用 A 块饼干换到 B 块
AC代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll K, A, B;
ll Ans;
int main(int argc, char *argv[]) {
scanf("%lld%lld%lld", &K, &A, &B);
if (A >= B - 1 || K <= A - 1) {
printf("%lld\n", K + 1);
return 0;
}
Ans = 1;
K -= A - 1; Ans += A - 1;
Ans -= (K / 2) * A;
Ans += (K / 2) * B;
if (K & 1) Ans++;
printf("%lld\n", Ans);
return 0;
}