HDU多校Round 3

Solved:4

rank:268

 

C. Dynamic Graph Matching  状压DP一下

#include <stdio.h>
#include <algorithm>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

ll dp[1 << 10];
ll ans[7];
int num[1 << 10];

void work()
{
    int len = 1 << 10;
    for(int i = 1; i < len; i++)
    {
        int x = i;
        while(x)
        {
            if(x & 1) num[i]++;
            x >>= 1;
        }
    }
}


int main()
{
    work();
    int T;
    scanf("%d", &T);
    while(T--) 
    {
        int n, m;
        scanf("%d%d", &n, &m);
        memset(dp, 0, sizeof(dp));
        memset(ans, 0, sizeof(ans));
        dp[0] = 1;
                
        char s[5];
        int len  = 1 << n;
        for(int i = 1; i <= m; i++)
        {
            int a, b;
            scanf("%s", s);
            scanf("%d%d", &a, &b);
            a--, b--;
            
            int tmp = (1 << a) | (1 << b);
            for(int i = 1; i < len; i++)
            {
                if(num[i] & 1) continue;
                if((i & tmp) == tmp)
                {
                    if(s[0] == '+')
                    {
                        dp[i] = (dp[i] + dp[i - tmp]) % mod;
                        ans[num[i] / 2] += dp[i - tmp];
                        ans[num[i] / 2] %= mod;
                    }
                    else
                    {
                        dp[i] -= dp[i - tmp];
                        dp[i] = (dp[i] + mod) % mod;
                        ans[num[i] / 2] -= dp[i - tmp];
                        ans[num[i] / 2] += mod;
                        ans[num[i] / 2] %= mod;
                    }
                }    
            }
            for(int i = 1; i <= n / 2; i++)
            {
                if(i == 1) printf("%d", ans[i]);
                else printf(" %d", ans[i]);    
            }
            puts("");
        }
    }
    return 0;
}
View Code

 

D. Euler Function

#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int getphi(int o)
{
    int res = o;
    int n = o;
    for(int i = 2; i * i <= n; i++)
    {
        if(n % i == 0)
        {
            res -= res / i;
            while(n % i == 0) n /= i;
        }
    }
    if(n > 1)  res -= res / n;
    return res;
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n;
        scanf("%d", &n);
        if(n == 1) printf("5\n");
        else if(n == 2) printf("7\n");
        else printf("%d\n", n + 5);
    }
    return 0;
}
View Code

 

L. Visual Cube

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;

char tu[205][205];

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);

        int lie = a * 2 + 1 + b * 2;
        int hang = c * 2 + 1 + b * 2;

        for(int i = 1; i <= hang; i++)
            for(int j = 1; j <= lie; j++)
                tu[i][j] = '.';

        for(int i = 1; i <= hang; i += 2)
            for(int j = 1; j <= lie; j += 2)
                tu[i][j] = '+';

        for(int i = 1; i <= hang; i += 2)
            for(int j = 2; j <= lie; j += 2)
                tu[i][j] = '-';

        for(int i = 2; i <= hang; i+= 2)
            for(int j = 1; j <= lie; j += 2)
                tu[i][j] = '|';

        int in = 0;
        int jn = b * 2 + 1;
        for(int i = 1; i <= b; i++)
        {
            in += 2;
            jn -= 2;
            for(int j = 1; j <= a + 1; j++)
            {
                tu[in][jn + (j - 1) * 2] = '.';
                tu[in][jn + (j - 1) * 2 + 1] = '/';
            }
        }

        int inj = lie + 1;
        int inh = 1;
        for(int i = 1; i <= b; i++)
        {
            inj -= 2;
            inh += 2;
            for(int j = 1; j <= c; j++)
            {
                tu[inh + (j - 1) * 2][inj] = '.';
                tu[inh + (j - 1) * 2 + 1][inj] = '/';
            }
        }

        int len = b * 2 + 1;
        for(int i = 1; i <= b * 2; i++)
        {
            len--;
            for(int j = 1; j <= len; j++)
                tu[i][j] = '.';
        }

        len = b * 2 + 1;
        for(int i = hang; i >= hang - b * 2; i--)
        {
            len--;
            for(int j = lie - len + 1; j <= lie; j++)
                tu[i][j] = '.';
        }

        for(int i = 1; i <= hang; i++)
        {
            for(int j = 1; j <= lie; j++)
                printf("%c", tu[i][j]);
            puts("");
        }
    }
    return 0;
}
View Code

 

posted @ 2018-07-30 22:49  lwqq3  阅读(134)  评论(0编辑  收藏  举报