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
6
题解:各种考虑,细心点。。。。
ac代码:
 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int MAXN=;
typedef long long LL;
int cmp(LL a,LL b){
return a>b;
}
int main(){
int T,N;
LL m[MAXN];
scanf("%d",&T);
while(T--){
scanf("%d",&N);
LL x,ans=;
int zheng=,fu=,o=;
for(int i=;i<N;i++){
scanf("%I64d",&x);
if(x>)ans*=x,zheng++;
else if(x<)m[fu++]=-x;
else o++;
}
if(!zheng){
if(!fu){
puts("");continue;
}
else if(o&&fu==){
puts("");continue;
}
else if(!o&&fu==){
printf("%I64d\n",-m[]);
continue;
}
}
if(fu==){
printf("%I64d\n",ans);continue;
}
sort(m,m+fu,cmp);
//for(int i=0;i<fu;i++)printf("%d ",m[i]);puts("");
for(int i=;i<(fu/)*;i++)ans*=m[i];
printf("%I64d\n",ans);
}
return ;
}

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
1
wa代码:
 HACK
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
int cmd(int a,int b){
return a>b;
}
int main(){
__int64 T,N,M;
scanf("%I64d",&T);
__int64 fac[];
while(T--){
scanf("%I64d%I64d",&N,&M);
if(M%N!=){
puts("-1");
continue;
}
__int64 t=;
__int64 n=N;
for(__int64 i=;i<=n;i++){
if(n%i==){
fac[t++]=i;
}
}
n=M/N;
__int64 ans=;
sort(fac,fac+t,cmd);
for(__int64 i=;i<t;i++){
while(n%(fac[i])==)n/=fac[i],ans++;
}
// for(int i=0;i<t;i++)printf("%d ",fac[i]);puts("");
if(n==)printf("%I64d\n",ans);
else puts("-1");
}
return ;
}

BC第二场的更多相关文章

  1. 本周进步要点20161023(含李笑来第二场live笔记要点)

    本周主要忙于去武汉参加iDOF2016智能数字油田会议,会上做了题为“油田SOA及云平台的系统思考与实践”的报告,为了准备这篇报告,用到了一些以前学过的知识,具体内容见“参加iDOF2016会议的收获 ...

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

    2014百度之星预赛(第二场)--Best Financing Problem Description 小A想通过合理投资银行理財产品达到收益最大化.已知小A在未来一段时间中的收入情况,描写叙述为两个 ...

  3. Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)

    Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...

  4. 2018牛客暑期ACM多校训练营第二场(有坑未填)

    第二场终于等来学弟 开始(被队友带飞)的开心(被虐)多校之旅 A   run A题是一个递推(dp?)+前缀和 因为看数据量比较大 就直接上前缀和了 一个比较简单的递推 没有太多难点 签到题 需要注意 ...

  5. 2018牛客网暑假ACM多校训练赛(第二场)E tree 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round2-E.html 题目传送门 - 2018牛客多校赛第二场 E ...

  6. NOI.AC NOIP模拟赛 第二场 补记

    NOI.AC NOIP模拟赛 第二场 补记 palindrome 题目大意: 同[CEOI2017]Palindromic Partitions string 同[TC11326]Impossible ...

  7. DevOps Workshop 研发运维一体化(北京第二场) 2016.04.27

    北京不亏为首都,人才济济,对微软DevOps解决方案感兴趣的人太多.我们与微软公司临时决定再家一场培训. 我之前在博客中(DevOps Workshop 研发运维一体化第一场(微软亚太研发集团总部)h ...

  8. CTF-i春秋网鼎杯第二场misc部分writeup

    CTF-i春秋网鼎杯第二场misc部分writeup 套娃 下载下来是六张图片 直接看并没有什么信息 一个一个查看属性 没有找到有用信息 到winhexv里看一下 都是标准的png图片,而且没有fla ...

  9. 2018 计算之道初赛第二场 阿里巴巴的手机代理商(困难)(反向可持久化Trie)

    阿里巴巴的手机代理商(困难) 阿里巴巴的手机代理商正在研究 infra 输入法的新功能.他们需要分析单词频率以改进用户输入法的体验.于是需要你在系统内核里面写一个 API. API 有如下功能: 添加 ...

随机推荐

  1. Android 图片平铺效果实现的3种方法

    Html中平铺的效果,那么我们都是怎么样才能实现的那,我们其实主要用到的就是api,我们一开始new一个bitmap,就可以了,那么我们就来说说第二种方法,那就在用到了xml,上面我们说了两个方法,但 ...

  2. JS的匿名函数和递归应用

    今天有项目需要用到JS的递归,开始按照php的实现方法,发现不行,后来只能使用arguments.callee. 简单的例子,如下 var act = 'if(num <= 1){return ...

  3. codeforces 21D. Traveling Graph 状压dp

    题目链接 题目大意: 给一个无向图, n个点m条边, 每条边有权值, 问你从1出发, 每条边至少走一次, 最终回到点1. 所走的距离最短是多少. 如果这个图是一个欧拉回路, 即所有点的度数为偶数. 那 ...

  4. 程序员眼里IE浏览器是什么样的

    主流浏览器之争从上个世纪开就开始,已经持续了很长的时间.就在几年前,IE还是最主流的web浏览器.但现在形势完全不同了,人们都在笑话IE,纷纷转向其它浏览器.今天,我向大家分享一下针对IE的搞笑图片, ...

  5. RedHat Enterprise Linux 6.3 安装Oracle Database 11g

    按照以下文章正确将oracle安装在linux上 http://yiyiboy2010.iteye.com/blog/1670795 http://mirrors.163.com/centos/6.5 ...

  6. Oracle Spatial-元数据及SDO_GEOMETRY

    一.空间表的元数据 将表的SDO_GEOMETRY列的所有对象作为一个空间层.Spatial需要对所有空间对象进行验证.创建索引和查询.此时需要为图层指定适当的元数据,该数据包含如下信息:维度.维度边 ...

  7. poj1657---chessboard

    对棋盘横纵坐标的解读 str1="f3" str2="e9" x=abs(str1[0]-str2[0]) y=abs(str1[1]-str1[1]) 如果x ...

  8. Android学习路线(六)为Android应用加入ActionBar

    Action bar 是你可以为你的应用的Activity实现的最为重要的设计元素之中的一个.它提供了集中UI特性.而且通过提供和其它的Android应用的一致性体验让你的应用可以非常快被用户熟悉.基 ...

  9. JS关闭页面无提示

    window.opener=null; window.open('','_self'); window.close();

  10. Oracle存储过程返回一张表数据

    在oracle数据库中你要在程序里得到一张表的数据就必须先创建游标和SQL Service不一样. --创建游标create or replace package pkg_Dataas type re ...