7.14被虐记

要仔细看题,不然PE和各种莫名其妙的WA就来了!今天开始继续写博客!

http://acm.hdu.edu.cn/showproblem.php?pid=3625

/*Accepted 3625 0MS 248K 818B C++ Yu */



#include<cstdio>

#include<cstring>



#define LL __int64

LL dp[21][21];

LL sum;

double ans[21][21], p[21][21];



void init()

{

    memset( dp, 0, sizeof dp);

    memset( ans, 0, sizeof ans);

    memset( p, 0, sizeof p);

    dp[1][1] = 1;

    sum = 1;

}



void cal()

{

    for( int i = 2; i <= 20; i ++)

    {

        dp[i][i] = 1;

        sum *= i; //N!

        for( int j = 1; j < i; j ++)

        {

            dp[i][j] = (i - 1) * dp[i - 1][j] + dp[i - 1][j - 1];

            ans[i][j] = ( 1.0 * ((i - 1) * dp[i - 1][j])) / sum;

        }

    }

    for( int i = 2; i <= 20; i ++)

    {

        for( int j = 1; j < i; j ++)

        {

            p[i][j] = ans[i][j];

            p[i][j] += p[i][j - 1];

        }

    }

}



int main()

{

    int T;

    int n, k;

    init();

    cal();

    scanf( "%d", &T);

    while( T --)

    {

        scanf( "%d%d", &n, &k);

        printf( "%.4lf\n", p[n][k]);

    }

    return 0;

}

http://acm.hdu.edu.cn/showproblem.php?pid=3626

/*Accepted 3626 0MS 244K 970 B C++ */



#include<cstdio>

#include<cstring>

#include<cstdlib>



const int MAXN = 1005;

typedef struct cood

{

    int x, y;

}C;



C c[MAXN], s[MAXN];

int n;



int cmp( const void *_p, const void *_q)

{

    C *p = (C *)_p;

    C *q = (C *)_q;

    if( p->x == q->x)

        return p->y - q->y;

    return p->x - q->x;

}



void input()

{

    for( int i = 0; i < n; i ++) {

        scanf( "%d%d", &c[i].x, &c[i].y);

        s[i].x = c[i].x, s[i].y = c[i].y;

    }

    qsort( s, n, sizeof s[0], cmp);

}



void output()

{

    bool flag = false;

    for( int i = 0; i < n; i ++){

        flag = false;

        for( int j = 0; j < n; j ++)

        {

            if( c[i].x < s[j].x && c[i].y < s[j].y )

            {

                printf( "%d %d\n", s[j].x, s[j].y);

                flag = true;

                break;

            }

        }

        if( !flag) printf( "-1 -1\n");

    }

}



int main()

{

    int cas = 0;

    while( scanf( "%d", &n) == 1)

    {

        if( 0 == n) break;

        if( cas ++) printf( "\n");

        printf( "Case %d:\n", cas);

        input();

        output();

    }

    return 0;

}

http://acm.hdu.edu.cn/showproblem.php?pid=3631

/*Accepted 3631 234MS 592K 1393 B C++ */

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;



const int MAXN = 305;

const int inf = 0x3f3f3f3f;

int map[MAXN][MAXN];

bool vis[MAXN];

int n, m, q;



void init()

{

    memset( vis, false, sizeof vis);

    for( int i = 0; i < n; i ++){

        for( int j = 0; j < n; j ++)

        {

            map[i][j] = inf;

        }

        map[i][i] = 0;

    }

}



void floyd( int k)

{

    for( int i = 0; i < n; i ++)

        for( int j = 0; j < n; j ++)

        {

            map[i][j] = min( map[i][j], map[i][k] + map[k][j]);

        }

}



void input()

{

    int a, b, c;

    while( m --)

    {

        scanf( "%d%d%d", &a, &b, &c);

        map[a][b] = min( c, map[a][b]);

    }

}



void operation()

{

    int op, x, y;

    while( q --)

    {

        scanf( "%d", &op);

        if( 0 == op) {

            scanf( "%d", &x);

            if(!vis[x]){

                vis[x] = true;

                floyd(x);

            }

            else {

                printf( "ERROR! At point %d\n", x);

            }

        }

        if( 1 == op) {

            scanf( "%d%d", &x, &y);

            if( !vis[x] || !vis[y]){

                printf( "ERROR! At path %d to %d\n", x, y);

            }

            else {

                if( map[x][y] != inf)

                    printf( "%d\n", map[x][y]);

                else

                    printf( "No such path\n");

            }

        }

    }

}



int main()

{

    int cas = 0;

    while( scanf("%d%d%d", &n, &m, &q) != EOF)

    {

        if( 0 == n && 0 == m && 0 == q) break;

        if( cas ++) printf( "\n");

        printf( "Case %d:\n", cas);

        init();

        input();

        operation();

    }

    return 0;

}

 

 

你可能感兴趣的:(7.14被虐记)