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

Codeforces Round #490 (Div. 3)

作者头像
attack
发布2018-07-04 15:10:58
2850
发布2018-07-04 15:10:58
举报

稳。。。。

题目区分度太小了。。。

A. Mishka and Contest

直接模拟

代码语言:javascript
复制
#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;
}

B. Reversing Encryption

直接模拟

代码语言:javascript
复制
#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;
}

C. Alphabetic Removals

 直接模拟

代码语言:javascript
复制
#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;
}

E. Reachability from the Capital

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

代码语言:javascript
复制
#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;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-06-27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • A. Mishka and Contest
  • B. Reversing Encryption
  • C. Alphabetic Removals
  • E. Reachability from the Capital
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档