Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

传送门:http://codeforces.com/contest/765

A题:给你家的名字,以及n张机票的起点和终点,Jinotega一开始在家,你要根据这些机票的起点和终点判断Jinotega最后是不是在家。直接记录起点和终点家出现的次数,如果相等说明Jinotega在家,否则不在家。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
char str[100];
char s[5];
int main()
{
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%s", str);
        str[3] = ‘\0‘;
        if (strcmp(str, s) == 0) ans++;
        if (strcmp(str + 5, s) == 0) ans--;
    }
    if (ans) puts("contest");
    else puts("home");
    return 0;
}

B题:这题题意我也看不太懂,大概是给你一个字符串,然后你要按字母顺序一个个覆盖,先覆盖a,再覆盖b,覆盖第一个a之前不能先遇到b、c……z。我是直接记录下每种字符第一次出现的位置,得到的序列如果是非递减的就输出YES,否则输出NO

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
char str[maxn];
int N[100];
int main()
{
    clr(N, 0x3f);
    scanf("%s", str + 1);
    int len = strlen(str + 1);
    for (int i = 1; i <= len; i++)
    {
        int id = str[i] - ‘a‘;
        if (N[id] == INF) N[id] = i;
    }
//    for (int i=0;i<26;i++)
//    printf("%d\n",N[i]);
    for (int i = 1; i < 26; i++)
        if (N[i] < N[i-1])
        {
            puts("NO");
            return 0;
        }
    puts("YES");
    return 0;
}

C题:题意是有两个人在比赛乒乓球,乒乓球是k分制(谁先到达k分谁赢),第一个人一共赢了a分,第二个人一共赢了b分,问他们最多有可能打多少局(必须是完整一局),如果不存在这种情况则输出-1。比较容易想到贪心,直接把每场比赛都当作是11:0,然后最后的余数再分给任意一场比赛就行了,所以答案就是a/k+b/k,然而这题有个坑点,就是如果a/k == 0,那么第一个人是无法处理b%k这一部分的,b同理,所以要特判一下。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;

int main()
{
    ll k, n, m;
    cin >> k >> n >> m;
    ll ans = n / k + m / k ;
    if (ans == 0) cout << -1 << endl;
    else
    {
        if (n / k == 0 && m % k) cout << -1 << endl;
        else if (m / k == 0 && n % k) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}

D题:题意是给你一个序列f(x),让你构造出一个序列使得 g(h(x))?=?x for all , and h(g(x))?=?f(x) for all ,这题是构造题,我是根据样例xjb构造的,至于为什么,我也不知道= =(逃)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int f[maxn], g[maxn], h[maxn], id[maxn];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &f[i]);
        h[f[i]] = f[i];
        g[i] = f[i];
    }
    int cnt = 1;
    for (int i = 1; i <= n; i++)
        if (h[i])
        {
            id[h[i]] = cnt;
            h[cnt] = h[i];
            cnt++;
        }
    for (int i = 1; i <= n; i++)
        g[i] = id[g[i]];
    for (int i = 1; i < cnt; i++)
        if (g[h[i]] != i)
        {
            puts("-1");
            return 0;
        }
    for (int i = 1; i <= n; i++)
        if (h[g[i]] != f[i])
        {
            puts("-1");
            return 0;
        }
    printf("%d\n", cnt - 1);
    for (int i = 1; i <= n; i++)
        printf("%d ", g[i]);
    puts("");
    for (int i = 1; i < cnt; i++)
        printf("%d ", h[i]);
    puts("");
    return 0;
}

这场最坑的莫过于c题,一开始就踩坑的我以为及时爬了上来,没想到最后还是因为写少了个else在终测挂掉了,最后靠着xjb写的D题上了蓝名,不过挂了c题还是很可惜的。

时间: 2024-08-24 13:50:16

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)的相关文章

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造

A. Neverending competitions time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (f

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B

Description Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate th

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding

地址:http://codeforces.com/contest/765/problem/E 题目: E. Tree Folding time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Vanya wants to minimize a tree. He can perform the following operation mu

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C - Table Tennis Game 2

地址:http://codeforces.com/contest/765/problem/C 题目: C. Table Tennis Game 2 time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Misha and Vanya have played several table tennis sets. Each set co

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) D. Artsem and Saunders

地址:http://codeforces.com/contest/765/problem/D 题目: D. Artsem and Saunders time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Artsem has a friend Saunders from University of Chicago. Saunders

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C

Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is r

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A

Description There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artse

Codeforces Round #397 (Div. 2)

A - Neverending competitions 没有任何价值..... 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int INF = 0x3f3f3f3f; 4 const int maxn = 100 + 5; 5 typedef long long LL; 6 typedef pair<int, int>pii; 7 8 char home[5]; 9 int main() 10 { 11 in

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/