BC第二场(又是零道)

GT and sequence

Accepts: 385

Submissions: 1467

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 65536/65536 K (Java/Others)

Problem Description

You are given a sequence of NN integers.

You should choose some numbers(at least one),and make the product of them as big as possible.

It guaranteed that the absolute value of any product of the numbers you choose in the initial sequence will not bigger than 2^{63}-12?63??−1.

Input

In the first line there is a number TT (test numbers).

For each test,in the first line there is a number NN,and in the next line there are NN numbers.

1 \leq T \leq 10001≤T≤1000 1 \leq N \leq 621≤N≤62

You‘d better print the enter in the last line when you hack others.

You‘d better not print space in the last of each line when you hack others.

Output

For each test case,output the answer.

Sample Input

1
3
1 2 3

Sample Output

6wa代码:
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #include<math.h>
 5 using namespace std;
 6 const int MAXN=1010;
 7 int cmd(int a,int b){
 8     return a>b;
 9 }
10 int main(){
11     int T,N;
12     int m[MAXN];
13     scanf("%d",&T);
14     while(T--){
15         scanf("%d",&N);
16         for(int i=0;i<N;i++){
17             scanf("%d",m+i);
18         }
19         sort(m,m+N,cmd);
20         long long ans=fabs(m[0]);
21         for(int i=1;i<N;i++){
22             if(fabs(ans*m[i])>ans)ans=fabs(ans*m[i]);
23         }
24         printf("%lld\n",ans);
25     }
26     return 0;
27 }

GT and numbers

Accepts: 146

Submissions: 939

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 65536/65536 K (Java/Others)

Problem Description

You are given two numbers NN and MM.

Every step you can get a new NN in the way that multiply NN by a factor of NN.

Work out how many steps can NN be equal to MM at least.

If N can‘t be to M forever,print -1−1.

Input

In the first line there is a number TT.TT is the test number.

In the next TT lines there are two numbers NN and MM.

T\leq1000T≤1000, 1\leq N \leq 10000001≤N≤1000000,1 \leq M \leq 2^{63}1≤M≤2?63??.

Be careful to the range of M.

You‘d better print the enter in the last line when you hack others.

You‘d better not print space in the last of each line when you hack others.

Output

For each test case,output an answer.

Sample Input

3
1 1
1 2
2 4

Sample Output

0
-1
1wa代码:
 1 HACK
 2 #include<stdio.h>
 3 #include<math.h>
 4 #include<string.h>
 5 #include<algorithm>
 6 using namespace std;
 7 int cmd(int a,int b){
 8     return a>b;
 9 }
10 int main(){
11     __int64 T,N,M;
12     scanf("%I64d",&T);
13     __int64 fac[10010];
14     while(T--){
15         scanf("%I64d%I64d",&N,&M);
16         if(M%N!=0){
17             puts("-1");
18             continue;
19         }
20         __int64 t=0;
21         __int64 n=N;
22         for(__int64 i=2;i<=n;i++){
23             if(n%i==0){
24                 fac[t++]=i;
25             }
26         }
27         n=M/N;
28         __int64 ans=0;
29         sort(fac,fac+t,cmd);
30         for(__int64 i=0;i<t;i++){
31             while(n%(fac[i])==0)n/=fac[i],ans++;
32         }
33     //    for(int i=0;i<t;i++)printf("%d ",fac[i]);puts("");
34         if(n==1)printf("%I64d\n",ans);
35         else puts("-1");
36     }
37     return 0;
38 }
时间: 2024-08-21 17:54:41

BC第二场(又是零道)的相关文章

计蒜之道2015程序设计大赛初赛第二场——人人都有极客精神

计蒜之道2015程序设计大赛初赛第二场——人人都有极客精神 (一)体面 人人公司是一家极为鼓励极客精神的公司,当有重要的项目需要上线但又时间太紧,甚至需要当天上线的时候,往往会挂起海盗旗开启电子日期显示,让大家可以在对时间有更明确的感知的情况下,同心协力搞定重要的项目.海盗旗下方的电子屏显示的日期形式为 YYYYMMDD (年份占 4 位.月份占 2 位.天数占 2 位). 日期电子屏幕上每个数字对应的显示如下图: 从上图可以得知每个数字对应的笔画数,比如 2 的笔画数是 5,8 的笔画数是 7

2017计蒜之道 初赛 第二场 百度的科学计算器(简单)

/** 题目:2017计蒜之道 初赛 第二场 百度的科学计算器(简单) 链接:https://nanti.jisuanke.com/t/15504 题意:给一个合法的表达式,包含加号+.减号-.括号().数字常量,表达式中没有空格. 输入数据保证数字常量以及计算过程中数值绝对值均不超过 10^12??,对于浮点型数值常量,保证小数点后不超过 666 位. 思路:暴力模拟:python有函数可以直接调用. 坑点:如果表达式中出现过浮点数,那么输出结果保留6位小数, 否则输出整数,不出现小数. */

2014百度之星初赛(第二场)——Best Financing

2014百度之星初赛(第二场)--Best Financing Problem Description 小A想通过合理投资银行理财产品达到收益最大化.已知小A在未来一段时间中的收入情况,描述为两个长度为n的整数数组dates和earnings,表示在第dates[i]天小A收入earnings[i]元(0<=i<n).银行推出的理财产品均为周期和收益确定的,可描述为长度为m的三个整数数组start.finish和interest_rates, 若购买理财产品i(0<=i<m),需要

2014百度之星预赛(第二场)——Best Financing

2014百度之星预赛(第二场)--Best Financing Problem Description 小A想通过合理投资银行理財产品达到收益最大化.已知小A在未来一段时间中的收入情况.描写叙述为两个长度为n的整数数组dates和earnings,表示在第dates[i]天小A收入earnings[i]元(0<=i<n).银行推出的理財产品均为周期和收益确定的,可描写叙述为长度为m的三个整数数组start.finish和interest_rates, 若购买理財产品i(0<=i<m

【补题】组队训练第二场 &amp; 个人训练第一场

组队第二场: C题 CodeForces Gym 100735D 题意:给你N个木棍,问他们能拼成多少个三角形. 思路:从小到大排序,然后贪心地去取. 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 #include<vector> 7 #include<set> 8

百度之星2014初赛第二场

A. Scenic Popularity http://acm.hdu.edu.cn/showproblem.php?pid=4831 思路:景点区会控制休息区的Hot值,我们建立休息区到它最近的景点区的关系,注意处理冲突. 查询和修改都暴力进行,预处理关系,从左到右,然后从右到左遍历一遍即可,更新时候,从被修改的p位置,向两边,与p有关的休息区进行更新.总的时间复杂度O(T*n*K),10^8左右,不到1s可以解决. const int maxn = 10000; const int maxh

【补题】多校联合训练第二场

第二场 1001 Is Derek lying? Problem Description Derek and Alfia are good friends.Derek is Chinese,and Alfia is Austrian.This summer holiday,they both participate in the summer camp of Borussia Dortmund.During the summer camp,there will be fan tests at i

将Linux和开源解决方案带到Azure云中第二场培训

因福州微软孵化器需要,3月27日下午给入孵企业进行第二场将Linux和开源解决方案带到Azure云中的培训. 本次培训的内容有: 概述:将开源技术带入 Azure 云中 Linux and OSS on Azure 如何将定制的 Linux & FreeBSD 环境迁入到 Azure Azure 上 Linux 虚拟机创建并通过 DSC For Linux 扩展来管理 在 Azure 中创建和管理 Docker 多容器环境

HDU 5742 It&#39;s All In The Mind (贪心) 2016杭电多校联合第二场

题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a,int b) { if(!b) return a; return gcd(b,a%b); } int main() { int t; ci