第一次打AtCoer的比赛,网络卡到爆炸,页面都打不开……体验极差(所以题目也不想补了

A - Anti-Adjacency

Description:

Determine if we can choose K K K different integers between 1 1 1 and N N N (inclusive) so that no two of them differ by 1 1 1 .

Input:

Input is given from Standard Input in the following format:

N N N K K K

  • 1 N , K 100 1≤N,K≤100 1N,K100
  • N N N and K K K are integers.

Output

If we can choose K K 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 ] [1,n] [1,n] 内能否拿出不连续的 k k k 个数

[ 1 , n ] [1,n] [1,n] 内最多可取的不连续数字数量为 n 2 \lceil \frac{n}{2} \rceil 2n ,所以直接和 k k 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 1,2,3 1,2,3 and 4 4 4 . Also, there are three roads. The ii-th road connects different towns a i ai ai and b i bi 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:

a 1 a_1 a1 b 1 b_1 b1
a 2 a_2 a2 b 2 b_2 b2
a 3 a_3 a3 b 3 b_3 b3

  • 1 a i , b i 4 ( 1 i 3 ) 1≤ai,bi≤4(1≤i≤3) 1ai,bi4(1i3)
  • a i ai ai and b i bi bi are different. ( 1 i 3 ) (1≤i≤3) (1i3)
  • 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 K K times in total, in the order he likes:

  • Hit his pocket, which magically increases the number of biscuits by one.
  • Exchange A A A biscuits to 1 1 1 yen.
  • Exchange 1 1 1 yen to B B B biscuits.

Find the maximum possible number of biscuits in Snuke’s pocket after K K K operations.

Input:

Input is given from Standard Input in the following format:

K K K A A A B B B

  • 1 K , A , B 1 0 9 1≤K,A,B≤10^9 1K,A,B109
  • K , A K,A K,A and B B B are integers.

Output:

Print the maximum possible number of biscuits in Snuke’s pocket after K K 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 1 1 块饼干和 0 0 0 元钱,每次操作他可以加一块饼干或用 A A A 块饼干换 1 1 1 元钱或用 1 1 1 元钱换 B B B 块饼干,求 K K K 次操作后的饼干数量最大值

Snuke 每次用 A A A 块饼干换到 B B B 块需要进行 2 2 2 次操作,所以当 A B 1 A\ge B-1 AB1 时没有直接增加一块饼干更优否则就每两次用 A A A 块饼干换到 B B 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;
}