Codeforces Round #395 (Div. 2) 题解

Posted AC_Arthur

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #395 (Div. 2) 题解相关的知识,希望对你有一定的参考价值。

比赛链接:

本次比赛解决3题(好水呀QAQ)

A. Taymyr is calling you

水题暴力

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <ctime>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 1000000000 + 7;
const int INF = 0x3f3f3f3f;
// & 0x7FFFFFFF 0xcf
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 100;
int T,n,m,z;


int main() 
//    ios::sync_with_stdio(false);
//    srand((unsigned)time(NULL));
//    freopen("out.txt","w",stdout);
//    freopen("in.txt","r",stdin);
//    scanf("%d",&T);

    scanf("%d%d%d", &n, &m, &z);
    int ans = 0;
    for(int i = 1; i <= z; i++) 
        if(i % n == 0 && i % m == 0) ++ans;
    
    printf("%d\\n", ans);
    return 0;

B. Timofey and cubes

从两边向中间,根据变换次数奇偶来改变

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <ctime>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 1000000000 + 7;
const int INF = 0x3f3f3f3f;
// & 0x7FFFFFFF 0xcf
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 2e5+10;
int T,n,m,z,a[maxn];


int main() 
//    ios::sync_with_stdio(false);
//    srand((unsigned)time(NULL));
//    freopen("out.txt","w",stdout);
//    freopen("in.txt","r",stdin);
//    scanf("%d",&T);

    scanf("%d", &n);
    for(int i = 1; i <= n; i++) 
        scanf("%d", &a[i]);
    

    for(int i = 1; i <= n/2; i++) 
        if(i&1) swap(a[i], a[n-i+1]);
    

    for(int i = 1; i <= n; i++) 
        printf("%d%c", a[i], i==n?'\\n':' ');
    

    return 0;

C. Timofey and a tree

思路:

随便找一个根做dfs序, 然后建立线段树维护区间最大最小值, 再dfs一遍, 枚举每个点做为根, 那么把线段分成了一些区间,  如果区间最大最小值相等, 那么就只有一种颜色。

细节参见代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <ctime>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 1000000000 + 7;
const int INF = 0x3f3f3f3f;
// & 0x7FFFFFFF 0xcf
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 2e5+10;
int T,n,m,z,a[maxn],in[maxn],idex = 0, out[maxn], minv[maxn<<2], maxv[maxn<<2];
int ans;
bool ok;
void pushup(int o) 
    minv[o] = min(minv[o<<1], minv[o<<1|1]);
    maxv[o] = max(maxv[o<<1], maxv[o<<1|1]);

void build(int l, int r, int o) 
    minv[o] = INF;
    maxv[o] = -INF;
    if(l == r) 
        minv[o] = maxv[o] = a[l];
        return ;
    
    int mid = (l + r) >> 1;
    build(l, mid, o<<1);
    build(mid+1, r, o<<1|1);
    pushup(o);

int querymin(int L, int R, int l, int r, int o) 
    if(L <= l && r <= R) 
        return minv[o];
    
    int mid = (l + r) >> 1;
    int ans = INF;
    if(L <= mid) ans = min(ans, querymin(L, R, l, mid, o<<1));
    if(mid < R) ans = min(ans, querymin(L, R, mid+1, r, o<<1|1));
    return ans;

int querymax(int L, int R, int l, int r, int o) 
    if(L <= l && r <= R) 
        return maxv[o];
    
    int mid = (l + r) >> 1;
    int ans = -INF;
    if(L <= mid) ans = max(ans, querymax(L, R, l, mid, o<<1));
    if(mid < R) ans = max(ans, querymax(L, R, mid+1, r, o<<1|1));
    return ans;


vector<int> g[maxn];
int c[maxn];
void dfs(int u, int fa) 
    int len = g[u].size();
    in[u] = ++idex;
    a[idex] = c[u];
    for(int i = 0; i < len; i++) 
        int v = g[u][i];
        if(v == fa) continue;
        dfs(v, u);
    
    out[u] = idex;

void dp(int u, int fa) 
    int len = g[u].size();
    bool flag = trueCodeforces Round #395 (Div. 2) C

Codeforces Round #395 (Div. 2)(未完)

Codeforces Round #395 A

Codeforces Round 395 div1

Codeforces Round 395 div1

Codeforces Round #395 (Div. 2) 题解