2019 ECNU Campus Invitational Contest

A.签到,模拟即可

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    char str[100];
    scanf("%s",str);
    int len = strlen( str );
    if( str[0] == '1' ){
        x = 10 + str[1] - '0';
        if( len == 4 ){
            y = str[2] - '0';
        }else{
            y = str[3] - '0' + 10;
        }
    }else{
        x = str[0] - '0';
        if( len == 3 ){
            y = str[1] - '0';
        }else{
            y = str[2] - '0'  + 10;
        }
    }
    printf("%d",(y+12-x)*( str[len-1] - '0' ) );
    return 0;
}

B.概率dp

题意:dp[ n ][ 0 ]代表考虑长度为n,先手为不含old maid 的胜率

          dp[ n ][ 1 ]代表长度为n,先手为含有old maid 的胜率】

#include <bits/stdc++.h>
using namespace std;
typedef int LL;
const LL maxn = 1e6 + 10;
double dp[maxn][2];
LL a1[maxn],a2[maxn];
int main()
{
    dp[1][0] = 1;
    dp[1][1] = 0;
    for( LL n = 2;n <= 1e6;n++ ){
        dp[n][0] = (1 + (double)( n-1 ) *( 1-dp[n-1][1] ) ) /(double)( n+1 );
        dp[n][1] = 1 - dp[n-1][0];
    }
    LL n,T;
    scanf("%d",&T);
    while( T-- ){
        scanf("%d",&n);
        for( LL i = 1;i<= n;i++ ){
            scanf("%1d",&a1[i]);
            a1[i] %= 2;
        }
        for( LL i = 1;i<= n;i++ ){
            scanf("%1d",&a2[i]);
            a2[i] %= 2;
        }
        LL s = 0;
        LL re = 0;
        for( LL i = 1;i <= n;i++ ){
            if( a1[i] == 1 && a2[i] == 1 ){
                re++;
            }else if( a1[i] == 1 && a2[i] == 0 ){
                s = 1;
                re++;
            }else if( a1[i] == 0 && a2[i] == 1 ){
                s = 0;
                re++;
            }
        }
        printf("%.10f\n",dp[re][s]);
    }
    return 0;
}

C.

D

E

F.签到,实测gets快的一批

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
map<string ,int> ma;
char str[100000000];
int main()
{
    int n;
    scanf("%d",&n);
    getchar();
    for( int i = 1;i <= n;i++ ){
        gets(str);
        int len  = strlen( str );
        string ss;
        ss += str[0];
        for( int  i = 0;i < len;i++ ){
            if( str[i] == ' ' ) ss += str[i+1];
        }
        ma[ss]++;
    }
    LL ans = 0;
    for(auto i = ma.begin();i != ma.end();i++ ){
        int x = i->second;
        ans += (LL)(x-1 )*x/2;
    }
    printf("%I64d",ans);
    return 0;
}

G

H.签到

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL gcd( LL x,LL y ){
    if( x < y ) swap( x,y );
    if( !y ) return x;
    return gcd( y,x%y );
}
int main()
{
    LL n,m,x,y;
    scanf("%I64d%I64d",&n,&m);
    if( n < m ){
         x = 1-n+2*m;
         y = 2*m;
        LL g = gcd( x,y );
        x /= g;
        y /= g;
    }else{
         x = m+1;
        y = 2*n;
        LL g = gcd( x,y );
        x /= g;
        y /= g;
    }
    printf("%I64d/%I64d",x,y);
    return 0;
}

I.三角等式,经讨论发现,只有当某一边长度已知时,才有可能出现冲突。我居然一开始往网络流和差分约束想了。。。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL maxn = 600;
const LL inf = 1e9;
LL a[maxn][maxn],n,vis[maxn][maxn];
bool floryd(){
    for( LL k = 1;k <= n;k++ ){
        for( LL i = 1;i <= n;i++ ){
            for( LL j = 1;j <= n;j++ ){
                if( a[i][k] + a[k][j] < a[i][j] ){
                    if( !vis[i][j] ) return false;
                    a[i][j] = a[i][k] + a[k][j];
                }
            }
        }
    }
    return true;
}
int main()
{
    LL T;
    scanf("%I64d",&T);
    while( T-- ){
        scanf("%I64d",&n);
        memset( vis,0,sizeof( vis ) );
        for( LL i = 1;i <= n;i++ ){
            for( LL j = 1;j <= n;j++ ){
                scanf("%I64d",&a[i][j]);
            }
        }
        bool flag = true;
        for( LL i = 1;i <= n;i++ ){
            for( LL j = 1;j <= n;j++ ){
                if( i == j ){
                    if( a[i][j] != -1 && a[i][j] != 0 ){
                        flag = false;
                        break;
                    }
                    a[i][j] = 0;
                    continue;
                }
                if( a[i][j] != a[j][i] ){
                    if( a[i][j] == -1 ){
                        a[i][j] = a[j][i];
                    }else if( a[j][i] == -1 ){
                        a[j][i] = a[i][j];
                    }else{
                        flag = false;
                        break;
                    }
                }
                if( (a[i][j] == a[j][i]) && a[i][j] == -1 ){
                    a[i][j] = a[j][i] = inf;
                    vis[i][j] = vis[j][i] = 1;
                }
            }
            if( !flag ) break;
        }
        if( !flag ){
            printf("NO\n");
            continue;
        }
        flag = floryd();
        if( flag ){
            printf("YES\n");
            for( LL i = 1;i <= n;i++ ){
                for( LL j = 1;j <= n;j++ ){
                    printf("%I64d ",a[i][j]);
                }
                printf("\n");
            }
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

J

K

L.这题应该算模拟吧,反正就是从大往小考虑,小的插空

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    LL T,c1,c2,c3,c4,c5,c6;
    scanf("%I64d",&T);
    LL ans = 0;
    while( T-- ){
        ans = 0;
        scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&c1,&c2,&c3,&c4,&c5,&c6);
        ans += c6;
        ans += c5;  c1 -= c5;
        ans += c4;
        if( c2 > 0 ){
            if( c4 > c2 ) c1 -= (c4-c2) * 2;
            c2 -= min( c2,c4 );
        }else{
            c1 -= c4 * 2;
        }
        if( c3 % 2 == 0 ){
            ans += c3/2;
            c3 = 0;
        }
        else{
            ans += c3/2;
            ans++;
            c3 = 1;
        }
        if( c3 > 0 ){
            c3--;
            if( c2 > 0 ){
                c2--;
                c1--;
            }else{
                c1 -= 3;
            }
        }
        LL mod;
        if( c2 > 0 ){
            ans += c2 / 3;
            mod = c2 % 3;
            if( mod ){
                ans++;
                c1 -= 6 - mod * 2;
            }
        }
        if( c1 > 0 ){
            ans += c1 / 6;
            mod = c1 % 6;
            if( mod ) ans++;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值