首页 > 代码库 > 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)

传送门: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;
}
View Code

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;
}
View Code

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;
}
View Code

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;
}
View Code

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

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