Codeforces Round #490 (Div. 3)

稳。。。。

题目区分度太小了。。。

 

A. Mishka and Contest

直接模拟

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1e6 + 10;
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 a[MAXN], vis[MAXN];
int main() {
#ifdef WIN32
//    freopen("a.in", "r", stdin);
#endif
    int N = read(), k = read();
    for(int i = 1; i <= N; i++) a[i] = read();
    int ans = 0;
    for(int i = 1; i <= N; i++) 
        if(a[i] <= k) ans++, vis[i] = 1;
        else break;
    for(int i = N; i >= 1; i--) 
        if(a[i] <= k && vis[i] == 0) ans++;
        else break;
    printf("%d", ans);
    return 0;
}
A

B. Reversing Encryption

直接模拟

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1e6 + 10;
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;
}
char s[MAXN];
int N;
void print(char *s) {
    for(int i = 1; i <= N; i++)
        putchar(s[i]); puts("");
}
int main() {
#ifdef WIN32
//    freopen("a.in", "r", stdin);
#endif
    scanf("%d", &N);
    scanf("%s", s + 1);
    for(int i = 1; i <= N; i++) 
        if(N % i == 0)
            reverse(s + 1, s + i + 1);
    print(s);
    return 0;
}
B

C. Alphabetic Removals

 直接模拟

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = 1e6 + 10;
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, K;
vector<int>v[27];
char s[MAXN];
int main() {
#ifdef WIN32
//    freopen("a.in", "r", stdin);
#endif
    N = read(), K = read();
    scanf("%s", s + 1);
    for(int i = 1; i <= N; i++) 
        v[s[i] - 'a'].push_back(i);
    for(int i = 0; i <= 25 && K > 0; i++)
            for(int j = 0; j < v[i].size()&& K > 0; j++, K--) 
                s[v[i][j]] = '#';
    for(int i = 1; i <= N; i++) 
        if(s[i] != '#')
            putchar(s[i]);
    return 0;
}
C

E. Reachability from the Capital

tarjan完后求有多少个入度为$0$的点

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
const int MAXN = 1e6 + 10;
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, M, S;
struct Edge {
    int u, v, nxt;
}E[MAXN];
int head[MAXN], num = 1;
inline void AddEdge(int x, int y) {
    E[num] = (Edge){x, y, head[x]};
    head[x] = num++;
}
stack<int>s;
int dfn[MAXN], low[MAXN], color[MAXN], colornum = 0, tot = 0, vis[MAXN], siz[MAXN];
void tarjan(int x) {
    dfn[x] = low[x] = ++tot;
    s.push(x);
    vis[x] = 1;
    for(int i = head[x]; i != -1; i = E[i].nxt) {
        int to = E[i].v;
        if(!dfn[to]) tarjan(to), low[x] = min(low[x], low[to]);
        else if(vis[to]) low[x] = min(low[x], dfn[to]);
    }
    if(dfn[x] == low[x]) {
        int h;
        colornum++;
        do {
            h = s.top(); s.pop();
            color[h] = colornum;
            vis[h] = 0;
        }while(h != x);
    }
}
bool happen[MAXN];
vector<int> v[MAXN];
int ans = 0;
void dfs(int x) {
    vis[x] = 1;
    for(int i = 0; i < v[x].size(); i++) {
        int to = v[x][i];
        if(!vis[to])
            ans++, dfs(to);
    }
}
int inder[MAXN];
int main() {
#ifdef WIN32
    //freopen("a.in", "r", stdin);
#endif    
    memset(head, -1, sizeof(head));
    N = read(); M = read(); S = read();
    for(int i = 1; i <= M; i++) {
        int x = read(), y = read();
        AddEdge(x, y);
    }
    for(int i = 1; i <= N; i++) 
        if(!color[i])
            tarjan(i);
    memset(vis, 0, sizeof(vis));
    for(int i = 1; i <= N; i++) 
        for(int j = head[i]; j != -1; j = E[j].nxt) 
            if(color[E[j].u] != color[E[j].v])
                inder[color[E[j].v]]++;
    for(int i = 1; i <= colornum; i++)
        if(inder[i] == 0)
            ans++;
    if(inder[color[S]] == 0) ans--;
    printf("%d", ans);
    return 0;
}
E

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值