Codeforces Round #288 (Div. 2) A,B,C,D,E

A:一个一个点向图里面加,判断其所在的位置与其他的点是否可以构成小矩形就可以了。

B:贪心,如果前面的偶数有比他小的就找到一个最靠前的交换,如果前面的偶数都比它小,就找一个最靠后的交换。

C:贪心,把蜡烛尽可能的放在恶魔,来之前,这样可以充分利用蜡烛的时间,模拟一下,不停地向前方就可以了。如果蜡烛时间小于需要的数目,一定不可以。

const int maxn = 2010;

int vis[maxn];
int num[maxn];

int main()
{
    int m, t, r;
    while(cin >>m>>t>>r)
    {
        for(int i = 1; i <= m; i++)
            scanf("%d",&num[i]);
        if(r > t)
        {
            puts("-1");
            continue;
        }
        int ans = 0;
        memset(vis, 0, sizeof(vis));
        for(int i = 1; i <= m; i++)
        {
            int x = num[i]-1;
            while(vis[num[i]+1000] < r)
            {
                for(int k = x-1; k <= x+t; k++)
                    vis[k+1000]++;
                ans++;
                x --;
            }
        }
        cout<<ans<<endl;
    }
}

D:欧拉路径+打印路径。

判断欧拉路径的方法是,统计出来他的度(入度+, 出度-)。如果所有的度均为0,或者只有一对度数为(+1,-1)的,那么就可以构成路径。但是这题还必须保证字符串的数目,所以判断之后,还有跑一遍dfs求出长度,判断长度是否满足条件。

打印路径的时候,先dfs再保存边,这样可以保证一开始存的边一定是距离“起点”最远的。

const int maxn = 200010;
char str[maxn][10];

int deg[maxn];
int ans[maxn];
int vis[maxn];
int cur[maxn];

vector<pair<int, int> > G[maxn*3];

int cnt;

int Get(char x)
{
    if ('0' <= x && x <= '9')return x-'0';
    if ('a' <= x && x <= 'z')return x-'a'+10;
    return x-'A'+36;
}

int get_x(int x)
{
    return Get(str[x][0])*62+Get(str[x][1]);
}

int get_y(int y)
{
    return Get(str[y][1])*62+Get(str[y][2]);
}

void dfs(int x, int y)
{
    int xp;
    int n = G[x].size();
    while(cur[x] < n)
    {
        if(!vis[G[x][xp = cur[x]++].second])
        {
            vis[G[x][xp].second] = 1;
            dfs(G[x][xp].first, G[x][xp].second);
        }
    }
    ans[cnt++] = y;
}

bool judge(int n)
{
    int x = 0;
    int y = 0;
    int pos = get_x(0);
    for(int i = 0; i < 62*62+100; i++)
    {
        if(deg[i] > 1 || deg[i] < -1) return false;
        if(deg[i] == 1)
        {
            x++;
            pos = i;
        }
        if(deg[i] == -1) y++;
    }
    if(x != y || x > 1) return false;
    dfs(pos, -1);
    cnt--;
    return cnt >= n;
}

int main()
{
    int n;
    while(cin >>n)
    {
        memset(cur, 0, sizeof(cur));
        memset(vis, 0, sizeof(vis));
        memset(deg, 0, sizeof(deg));
        cnt = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%s", str[i]);
            int x = get_x(i);
            int y = get_y(i);
            G[x].push_back(make_pair(y, i));
            deg[x]++;
            deg[y]--;
        }
        if(!judge(n))
        {
            cout<<"NO"<<endl;
            continue;
        }
        puts("YES");
        printf("%s",str[ans[cnt-1]]);
        for(int i = cnt-2; i >= 0; i--)
            printf("%s", str[ans[i]]+2);
        puts("");
    }
    return 0;
}

/*
6
abc
bca
cab
cad
adc
dca
*/
时间: 2024-10-02 18:44:14

Codeforces Round #288 (Div. 2) A,B,C,D,E的相关文章

Codeforces Round #288 (Div. 2)

A. Pasha and Pixels 题目大意:给出n*m的棋盘,初始为全白,每次在上面使一个格子变黑,问多少次的时候使得棋盘上出现2×2的黑格 思路:模拟 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<queue> 5 #define maxn 900000 6 #define LL long long 7 using namespace std; 8 boo

Codeforces Round #288 (Div. 2) 待续

A. Pasha and Pixels ( 暴力 ) 题意:给一个n*m的矩阵染色(初始为全白),如果在k步之内染出一个2*2的矩阵,输出最小步数,否则输出0 分析:brute force #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int M[ 1010 ][ 1010 ]; int step, r, c, k

Codeforces Round #288 (Div. 2)B(字符串)

题意:交换两个数,使得交换后的数是偶数且尽可能大: KEY:分情况,1末尾数为偶数,即找到比它小的偶数交换,假如没有比它小的偶数,不用交换.2末尾数是奇数,再分情况,<1>全都是奇数(这个可以在一开始就判断掉),即输出-1,<2>有一个偶数,无论如何谁大谁小都要交换,<3>全部偶数都比奇数大,从n - 2(n是字符串长度)开始找到一个偶数交换即可,<4>如果有一些偶数比末尾数大,有些比它小,即从0开始找到比奇数小的那个偶数交换即可.其实是分类讨论.(有更好的

Codeforces Round #288 (Div. 2) ABCDE

A题 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 10 using namespace std; 11 12 #define LL

Codeforces Round #288 (Div. 2) A. Pasha and Pixels

A. Pasha and Pixels time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to

Codeforces Round #288 (Div. 2) B. Anton and currency you all know

B. Anton and currency you all know time limit per test 0.5 seconds memory limit per test 256 megabytes input standard input output standard output Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that

Codeforces Round #288 (Div. 2) C. Anya and Ghosts

C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lo

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i