您的位置:首页 > 其它

BC第二场

2015-10-17 21:04 495 查看

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=1010;
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=1;
int zheng=0,fu=0,o=0;
for(int i=0;i<N;i++){
scanf("%I64d",&x);
if(x>0)ans*=x,zheng++;
else if(x<0)m[fu++]=-x;
else o++;
}
if(!zheng){
if(!fu){
puts("0");continue;
}
else if(o&&fu==1){
puts("0");continue;
}
else if(!o&&fu==1){
printf("%I64d\n",-m[0]);
continue;
}
}
if(fu==1){
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=0;i<(fu/2)*2;i++)ans*=m[i];
printf("%I64d\n",ans);
}
return 0;
}


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[10010];
while(T--){
scanf("%I64d%I64d",&N,&M);
if(M%N!=0){
puts("-1");
continue;
}
__int64 t=0;
__int64 n=N;
for(__int64 i=2;i<=n;i++){
if(n%i==0){
fac[t++]=i;
}
}
n=M/N;
__int64 ans=0;
sort(fac,fac+t,cmd);
for(__int64 i=0;i<t;i++){
while(n%(fac[i])==0)n/=fac[i],ans++;
}
//    for(int i=0;i<t;i++)printf("%d ",fac[i]);puts("");
if(n==1)printf("%I64d\n",ans);
else puts("-1");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: