zoukankan      html  css  js  c++  java
  • 【OpenJ_Bailian

    拼点游戏

    Descriptions:

    C和S两位同学一起玩拼点游戏。有一堆白色卡牌和一堆蓝色卡牌,每张卡牌上写了一个整数点数。C随机抽取n张白色卡牌,S随机抽取n张蓝色卡牌,他们进行n回合拼点,每次两人各出一张卡牌,点数大者获得三颗巧克力,小者获得一颗巧克力,如果点数相同,每人各得二颗巧克力,使用过的卡牌不得重复使用。已知C和S取到的卡牌点数,请编程计算S最多和最少能得到多少颗巧克力。

    Input

    输入包含多组测试数据。 

    每组测试数据的第一行是一个整数n(1<=n<=1000),接下来一行是n个整数,表示C抽到的白色卡牌的点数,下一行也是n个整数,表示S抽到的蓝色卡牌的点数。 
    输入的最后以一个0表示结束

    Output

    对每组数据,输出一行,内容是两个整数用空格格开,分别表示S最多和最少可获得的巧克力数。

    Sample Input

    3
    92 83 71
    95 87 74
    2
    20 20
    20 20
    2
    20 19
    22 18
    0

    Sample Output

    9 5
    4 4
    4 4

    题目链接:

    https://vjudge.net/problem/OpenJ_Bailian-4005

    田忌赛马的加强版,参照田忌赛马,稍微改改就行

    田忌赛马链接:

    https://www.cnblogs.com/sky-stars/p/11073032.html

    AC代码

    #include <iostream>
    #include <cstdio>
    #include <fstream>
    #include <algorithm>
    #include <cmath>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <cstring>
    #include <map>
    #include <stack>
    #include <set>
    #include <sstream>
    #define mod 1000000007
    #define eps 1e-6
    #define ll long long
    #define INF 0x3f3f3f3f
    #define ME0(x) memset(x,0,sizeof(x))
    using namespace std;
    int n;
    //这就是田忌赛马好吗0.0  不会的看我田忌赛马博客  讲的比较细
    //  https://www.cnblogs.com/sky-stars/p/11073032.html
    int solve(int c[1005],int s[1005])
    {
        int ans=0;
        int cl=1,cr=n,sl=1,sr=n;
        while(sl<=sr)
        {
    //        cout<<sr<<"*       *"<<sl<<endl;
    //        cout<<s[sr]<<"    "<<c[cr]<<endl;
            if(s[sr]>c[cr])
            {
                --sr;
                --cr;
                ans+=3;
            }
            else if(s[sr]<c[cr])
            {
                ++sl;
                --cr;
                ans+=1;
            }
            else
            {
                if(s[sl]>c[cl])
                {
                    ++sl;
                    ++cl;
                    ans+=3;
                }
                else
                {
                    if(s[sl]<c[cr])
                    {
                        ++sl;
                        --cr;
                        ans+=1;
                    }
                    else
                    {
                        ++sl;
                        --cr;
                        ans+=2;
                    }
                }
            }
        }
        return ans;
    }
    int main()
    {
        while(cin>>n,n)
        {
            int a[1005];
            int b[1005];
            ME0(a);
            ME0(b);
            for(int i=1; i<=n; ++i)
                cin>>a[i];//C的卡牌
            for(int i=1; i<=n; ++i)
                cin>>b[i];//S的卡牌
            sort(a+1,a+1+n);
            sort(b+1,b+1+n);
            cout<<solve(a,b)<<" ";//求C的最大得分
            //每一局总分一定是4,//求出S的最大得分,就求出了C的最小得分
            cout<<4*n-solve(b,a)<<endl;
        }
    }
  • 相关阅读:
    06
    05
    继承
    0713作业
    0712作业
    0711作业
    福彩双色球作业
    0709作业
    选择语句+循环语句作业
    0706作业
  • 原文地址:https://www.cnblogs.com/sky-stars/p/11073068.html
Copyright © 2011-2022 走看看