zoukankan      html  css  js  c++  java
  • 第七届福建省大学生程序设计竞赛

    Problem 2264 Card Game (First Edition)

    题意:

      有2×n张牌,Fat brother 和 Maze两个人轮流取一张牌,不放回, 谁取的牌大谁就得一分。问Fat brother 得分的期望。

    题解:

      每个人赢的概率都是0.5。

    代码:

    #include<stdio.h>
    using namespace std;
    int main(){
        int T;
        scanf("%d",&T);
        for(int t = 1; t <= T; t++) {
            int n,x;
            scanf("%d",&n);
            for (int i = 0; i < n*2; i++){
                scanf("%d",&x);
            }
            printf("Case %d: %.2f
    ",t,n/2.0);
        }
        return 0;
    }
    View Code

    Problem 2265 Card Game (Second Edition)

    题意:

      Fat brother 和 Maze两个人分别有n张牌,每轮两个人都在自己的牌里面随便选一张,不放回, 谁取的牌大谁就得一分。问Fat brother 得分的期望。

    题解:

      将Fat brother每张牌能赢的次数加起来除以n。排个序在找就行了。

    代码:

    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    const int N = 10000 + 10;
    int a[N],b[N];
    int main(){
        int T,n;
        scanf("%d",&T);
        for(int t = 1; t <= T; t++) {
            scanf("%d",&n);
            for (int i = 0; i < n; i++){
                scanf("%d",&a[i]);
            }
            for (int i = 0; i < n; i++){
                scanf("%d",&b[i]);
            }
            sort(a,a+n);
            sort(b,b+n);
            int cnt = n-1,sum = 0;
            for (int i = n-1; i >=0; i--){
                while(a[i]<=b[cnt] && cnt>=0)
                    cnt--;
                if (cnt<0) break;
                if (a[i] > b[cnt]) sum+=cnt+1;
            }
            printf("Case %d: %.2f
    ",t,(double)sum/(double)n);
        }
        return 0;
    }
    View Code

    Problem 2266 Card Game (Third Edition)

    题意:

      Fat brother 和 Maze两个人分别有n张牌,每轮两个人都在自己的牌里面按顺序取一张,如果两人取的牌的和大于10就得一分,求得分。

    题解:

      遍历一下两个数组就行了。

    代码:

    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    const int N = 10000 + 10;
    int a[N],b[N];
    int main(){
        int T,n;
        scanf("%d",&T);
        for(int t = 1; t <= T; t++) {
            scanf("%d",&n);
            for (int i = 0; i < n; i++){
                scanf("%d",&a[i]);
            }
            for (int i = 0; i < n; i++){
                scanf("%d",&b[i]);
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                if (a[i]+b[i] > 10) {
                    ans++;
                }
            }
            printf("Case %d: %d
    ",t,ans);
        }
        return 0;
    }
    View Code

    Problem 2267 The Bigger the Better

    题意:

      给你一个长度为n的数字a和一个长度为m的数组b,每一个元素都是1~9,你每次可以从a或b中选最前面一个元素移动到c数组末尾,输出c数组字典序最大的结果。c数组最开始为空。

    题解:

       然后两个数组最前面那个元素不一样直接比较之后加到c数组末尾即可,当两个元素相同的时候,我们可以通过比较这两个数组的字典序来决定取哪个数组中的元素。我们可以直接用字符串存这两个数组,通过字符串比较函数来比较。不过要注意两个字符串长度不相同的情况。

    代码:

    #include <stdio.h>
    #include <string.h>
    const int N = 100000 + 10;
    char a[N],b[N],c[N*2];
    int main() {
        int T,n,m,x;
        while (~scanf("%d",&T)) {
            for (int t = 1; t <= T; ++t) {
                scanf("%d%d",&n,&m);
                for (int i = 0; i < n; ++i) {
                    scanf("%d",&x);
                    a[i] = x+'0';
                }
                for (int i = 0; i < m; ++i) {
                    scanf("%d",&x);
                    b[i] = x+'0';
                }
                a[n] = b[m] = '0';
                a[n+1] = b[m+1] = '';
                int cnt1=0,cnt2=0,cnt=0;
                while (cnt1<n&&cnt2<m) {
                    if (a[cnt1] < b[cnt2]) {
                        c[cnt++] = b[cnt2++];
                    }else if (a[cnt1] > b[cnt2]) {
                        c[cnt++] = a[cnt1++];
                    }else {
                        int fg = strcmp(a+cnt1,b+cnt2);
                        if (fg<0) {
                            while (a[cnt1] == b[cnt2] && cnt2<m)
                            c[cnt++] = b[cnt2++];
                        }
                        else {
                            while (a[cnt1] == b[cnt2] && cnt1<n)
                            c[cnt++] = a[cnt1++];
                        }
                    }
                }
                while (cnt1<n) c[cnt++] = a[cnt1++];
                while (cnt2<m) c[cnt++] = b[cnt2++];
                c[cnt] = '';
                printf("Case %d: %s
    ",t,c);
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    ES6中的基础语法
    let和const、var
    iframe框架
    ajax
    面试题
    移动端的点击延迟事件
    移动端如何设置字体
    swiper插件以及简介
    第十二章 systemctl管理脚本
    第十一章 awk命令
  • 原文地址:https://www.cnblogs.com/l999q/p/10893357.html
Copyright © 2011-2022 走看看