栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

第十二届国防科技大学程序设计竞赛(同步赛)-E题解

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

第十二届国防科技大学程序设计竞赛(同步赛)-E题解

链接:https://ac.nowcoder.com/acm/contest/35627/E
来源:牛客网
 

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

PaiGuDragon participated in the game of fake-blackjack.

Each card is written with a number from 111 to 101010. In the game, the PaiGuDragon can choose "shoot" or "stay".

If selecting "shoot",  PaiGuDragon will draw the card at the top of the stack.

 
If selecting "stay",  PaiGuDragon will end draw and count the sum of points.

If the total number of cards drawn exceeds 212121, then PaiGuDragon lose everything!

On the premise that the sum of points is less than or equal to 212121, the greater the sum of points, the stronger the card power.

As a clairvoyant, PaiGuDragon can see every card in the stack from top to bottom. So how many cards will the smart PaiGuDragon choose to draw to get the best result?

输入描述:

The first line contains an interger n(1≤n≤20)n(1 le n le 20)n(1≤n≤20) - the number of cards.
The second line contains nnn intergers - card points from top to bottom, each number is an interger between 111 and 101010.

输出描述:

Print a single integer, the number of cards PaiGuDragon will draw.

示例1

输入
3
10 9 3
输出

2

说明
In the first test case, PaiGuDragon will draw 222 cards and get 10+9=1910 + 9 = 1910+9=19 points. If it draws 333 cards, the sum will exceed 212121.

示例2

输入

6

1 2 3 4 5 6

输出

6

说明
In the second test case, PaiGuDragon will draw all cards, and get 1+2+3+4+5+6=211 + 2 + 3 + 4 +5 + 6 = 211+2+3+4+5+6=21 points!
题意

在n张牌中选取cnt张牌,使得cnt张牌的和小于等于21,输出cnt的最大值

#include
using namespace std;
int a[21];
int main(){
    int sum=0,cnt=0;
    int n;
    cin>>n;
    for(int i=0;i>x;
        a[i]=x;
    }
    for(int i=0;i21){
            break;
        }else{
            sum+=a[i];
            cnt++;
        }
    }
    cout<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/957928.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号