前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Codeforces Round #473 (Div. 2)

Codeforces Round #473 (Div. 2)

作者头像
attack
发布2018-08-01 11:18:33
1750
发布2018-08-01 11:18:33
举报

这场怎么都是异或啊qwq。。。

A. Mahmoud and Ehab and the even-odd game

直接判断奇偶性

代码语言:javascript
复制
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long 
using namespace std;
const int MAXN = 2 * 1e6 + 10, INF = 1e9 + 10, B = 63;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
main() { 
#ifdef WIN32
    //freopen("a.in", "r", stdin);
#endif
    int N = read();
    puts(N & 1 ? "Ehab" : "Mahmoud");
}

B. Mahmoud and Ehab and the message

维护出每个graph的最小值,输出即可,我咋还开了个map

代码语言:javascript
复制
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
#define int long long 
using namespace std;
const int MAXN = 2 * 1e6 + 10, INF = 1e9 + 10, B = 63;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, G, M;
string s[MAXN];
int val[MAXN], minval[MAXN];
map<string, int> ID;
main() { 
#ifdef WIN32
    //freopen("a.in", "r", stdin);
#endif
    memset(minval, 0x3f, sizeof(minval));
    N = read(); G = read(); M = read();
    for(int i = 1; i <= N; i++) 
        cin >> s[i];
        //cout << s << endl;
    for(int i = 1; i <= N; i++) 
        val[i] = read();
    for(int i = 1; i <= G; i++) {
        int num = read();
        for(int j = 1; j <= num; j++) {
            int x = read();
            ID[s[x]] = i;
        }
    }
    
    for(int i = 1; i <= N; i++)
        minval[ID[s[i]]] = min(minval[ID[s[i]]], val[i]);
    //for(int i = 1; i <= N; i++) printf("%d ", ID[s[i]]); puts("***");
    //for(int i = 1; i <= N; i++) printf("%d ", minval[ID[s[i]]]); puts("***");
    int ans = 0;
    string x;
    for(int i = 1; i <= M; i++) {
        cin >> x;
        ans += minval[ID[x]];
    }
    printf("%I64d", ans);
}

C. Mahmoud and Ehab and the wrong algorithm

我的构造思路比较奇葩,大概长这样。。

代码语言:javascript
复制
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
const int MAXN = 2 * 1e6 + 10, INF = 1e9 + 10, B = 63;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

main() { 
#ifdef WIN32
    //freopen("a.in", "r", stdin);
#endif
    int N = read();
    if(N == 2 || N == 3 || N == 4 || N == 5) printf("-1\n");
    else {
        printf("1 2\n");
        printf("1 3\n");
        printf("1 4\n");
        for(int i = 5; i <= N; i++) 
            printf("3 %d\n", i);
    }
    for(int i = 1; i <= N - 1; i++) 
        printf("%d %d\n", i, i + 1);
}

E. Mahmoud and Ehab and the xor-MST

打表后强上oeis

代码语言:javascript
复制
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
#define int long long 
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
map<int, int> ans;
int B(int x) {
    if(ans[x] ) return ans[x];
    if(x & 1) return ans[x] = 2 * B(x / 2) + (x / 2) + 1;
    else return ans[x] = 2 * B(x / 2) + x / 2;
}
main() { 
#ifdef WIN32
    //freopen("a.in", "r", stdin);
#endif
    ans[1] = 1;
    int N = read();
    printf("%I64d", B(N - 1));
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-06-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • A. Mahmoud and Ehab and the even-odd game
  • B. Mahmoud and Ehab and the message
  • C. Mahmoud and Ehab and the wrong algorithm
  • E. Mahmoud and Ehab and the xor-MST
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档