2020牛客暑期多校训练营(第九场)I .The Crime-solving Plan of Groundhog

题目链接

题目描述

Today, ZLZX has a mysterious case: Orange lost his down jacket hanging in his dorm room. Under the expectations of everyone, detective Groundhog took his small spoon of the artifact and started the journey to solve the case.

After an in-depth investigation of the northernmost mysterious room on each floor, Groundhog discovered {n}n mysterious numbers. As long as the clues conveyed by these numbers are deciphered, he can reveal the truth of the matter. The deciphering method is: using these numbers to generate two positive integers without leading zeros, and minimizing the product of these two positive integers is the final clue.

Then Groundhog wants to know: What is the smallest product?

As he continued to investigate in the room west of the new building, he gave you the question.

Concise meaning:Given n numbers between 0 and 9, use them to make two positive integers without leading zeros to minimize the product.

输入描述:

The first line of input is a single integer TTT,the number of test cases.
For each set of data:
Each test case begins with a single integer nnn, the count of numbers.
The next line are nnn numbers.

输出描述:

For each set of Case, an integer is output, representing the smallest product.

示例1

输入

1
4
1 2 2 1

输出

122

示例2

输入

2
5
1 3 2 1 2
3
1 1 0

输出

1223
10

思维题,很容易想到选一个最小的数字出来,再把剩下的数字拼成一个最小的数,然后相乘即可,注意两个数必须要是正数,且没有前导 000,可以对数组先进行排序,找到第一个不是 000 的位置,然后替换两次就能得到最小的数了,举个例子

0000123->替换第1个和第5个1000023->替换第2个和第6个1200003->1|200003

对第 222 个到第 nnn 个进行模拟乘法即可~
1.C++代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,t,a[N];
int main()
{scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;i++) scanf("%d",&a[i]);sort(a,a+n);int pos=0;while(!a[pos]) pos++;swap(a[0],a[pos]);swap(a[1],a[pos+1]);for(int i=1;i<n;i++) a[i]*=a[0];for(int i=n-1;i>1;i--) a[i-1]+=a[i]/10,a[i]%=10;for(int i=1;i<n;i++) printf("%d",a[i]);printf("\n");}return 0;
}

2.python代码如下:

t=int(input())
for i in range(t):n=int(input())a=input().split()a.sort()i=0while a[i]=='0':i+=1x=a[i]y=a[i+1]+'0'*i+"".join(a[i+2:])print(int(x)*int(y))

2020牛客暑期多校训练营(第九场)I .The Crime-solving Plan of Groundhog相关推荐

  1. 2020牛客暑期多校训练营(第九场)E题 Groundhog Chasing Death

    题意 计算 ∏ i = a b ∏ j = c d g c d ( x i , y j ) \prod_{i=a}^{b}\prod_{j=c}^{d}gcd(x^i,y^j) i=a∏b​j=c∏d ...

  2. E Groundhog Chasing Death(2020牛客暑期多校训练营(第九场))(思维+费马小定理+质因子分解)

    E Groundhog Chasing Death(2020牛客暑期多校训练营(第九场))(思维+费马小定理+质因子分解) 链接:https://ac.nowcoder.com/acm/contest ...

  3. 2020牛客暑期多校训练营(第六场)

    2020牛客暑期多校训练营(第六场) 额,睡了一下午,直接错过了比赛... 文章目录 A African Sort 题意: 题解: 代码: B Binary Vector C Combination ...

  4. 2020牛客暑期多校训练营(第四场)

    2020牛客暑期多校训练营(第四场) 这场属实有点难受 文章目录 A Ancient Distance B Basic Gcd Problem 题目 代码: C Count New String D ...

  5. 2020牛客暑期多校训练营(第一场)

    文章目录 A B-Suffix Array B Infinite Tree C Domino D Quadratic Form E Counting Spanning Trees F Infinite ...

  6. 2020牛客暑期多校训练营(第二场)

    2020牛客暑期多校训练营(第二场) 最烦英语题 文章目录 A All with Pairs B Boundary C Cover the Tree D Duration E Exclusive OR ...

  7. 2020牛客暑期多校训练营(第七场)J.Pointer Analysis

    2020牛客暑期多校训练营(第七场)J.Pointer Analysis 题目链接 题目描述 Pointer analysis, which aims to figure out which obje ...

  8. 2020牛客暑期多校训练营(第三场)A.Clam and Fish

    2020牛客暑期多校训练营(第三场)A.Clam and Fish 题目链接 题目描述 There is a fishing game as following: The game contains ...

  9. 2020牛客暑期多校训练营(第五场)——E Bogo Sort

    2020牛客暑期多校训练营(第五场)--E Bogo Sort 题目描述 Today Tonnnny the monkey learned a new algorithm called Bogo So ...

  10. 2020牛客暑期多校训练营(第一场)A B-Suffix Array(后缀数组,思维)

    链接:https://ac.nowcoder.com/acm/contest/5666/A 来源:牛客网 题目描述 The BBB-function B(t1t2-tk)=b1b2-bkB(t_1 t ...

最新文章

  1. iOS 数字滚动 类似于老 - 虎- 机的效果
  2. 今天开始搞CentOS 7
  3. keras Classifier 分类
  4. 有bug!用Pytorch Lightning重构代码速度更慢,修复后速度倍增
  5. 杭电1000 A + B Problem
  6. DOCTYPE声明对JS获取窗口宽度和高度的影响【转】
  7. 云炬创业政策学习笔记20210104
  8. 应届生是这辈子最大的一次优势,也是最后一次!
  9. execl用宏查询mysql_关于EXCEL能否用宏直接连到oracle数据库然后取数据
  10. .net core i上 K8S(五).netcore程序的hostip模式
  11. Jdk8一行代码读取文件
  12. 【Python笔记】字符串常见操作
  13. Go 1.15 正式发布;华为确认成立屏幕驱动芯片部门;微信 iOS 版 7.0.15 正式版发布| 极客头条
  14. 1.VC弹出打开文件/保存文件/选择文件对话框
  15. 缓存穿透,缓存击穿,缓存雪崩以及解决方案
  16. 如何在IOS上玩gba游戏(免越狱)
  17. android中界面布局文件放在,android界面布局详解.doc
  18. 电视剧《都挺好》弹幕数据分析
  19. 电脑时间不准怎么办?电脑时间不准怎么修复?
  20. @vuecomposition-apidistvue-composition-api.mjs in .node_modulesvue-demilibindex.mjs 报错

热门文章

  1. C语言,将1~9这9个数字分成三组,每组中的三个数排成一个三位的完全平方数,要求每个数字必须且只能用一次
  2. awb数据怎么计算_AWB参数概念
  3. 桃园 更新完列表 不显示服务器,桃园7月25日更新内容详解
  4. HDU 1814 Two_Sat
  5. WKwebview弹框报错Attempt to present UIAlertController on XXwhich is already presenting (null)
  6. python 读文件夹下面所有csv格式文件
  7. mtk编译android,[Android6.0][MTK6737] MTK 编译环境搭建
  8. 悼念!旷视首席科学家孙剑博士去世,享年 45 岁
  9. 在生鲜电商领域创业到底是怎样的一种苦逼体验?【创业者说】
  10. vue 生命周期图 + activated + deactivated