码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #473 (Div. 2)

时间:2018-06-16 16:14:45      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:else   min   long   sizeof   int   .com   algorithm   ons   最小   

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

A. Mahmoud and Ehab and the even-odd game

直接判断奇偶性

技术分享图片
#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");
}
A

B. Mahmoud and Ehab and the message

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

技术分享图片
#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);
}
B

C. Mahmoud and Ehab and the wrong algorithm

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

技术分享图片
#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);
}
C

技术分享图片 

E. Mahmoud and Ehab and the xor-MST

打表后强上oeis

技术分享图片
#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));
}
E

Codeforces Round #473 (Div. 2)

标签:else   min   long   sizeof   int   .com   algorithm   ons   最小   

原文地址:https://www.cnblogs.com/zwfymqz/p/9190667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!