zoukankan      html  css  js  c++  java
  • 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}-1263​​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 10001T1001 leq N leq 621N62

    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代码:
     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 typedef long long LL;
     8 int cmp(LL a,LL b){
     9     return a>b;
    10 }
    11 int main(){
    12     int T,N;
    13     LL m[MAXN];
    14     scanf("%d",&T);
    15     while(T--){
    16         scanf("%d",&N);
    17         LL x,ans=1;
    18         int zheng=0,fu=0,o=0;
    19         for(int i=0;i<N;i++){
    20             scanf("%I64d",&x);
    21             if(x>0)ans*=x,zheng++;
    22             else if(x<0)m[fu++]=-x;
    23             else o++;
    24         }
    25         if(!zheng){
    26             if(!fu){
    27                 puts("0");continue;
    28             }
    29             else if(o&&fu==1){
    30                 puts("0");continue;
    31             }
    32             else if(!o&&fu==1){
    33                 printf("%I64d
    ",-m[0]);
    34                 continue;
    35             }
    36         }
    37         if(fu==1){
    38                 printf("%I64d
    ",ans);continue;    
    39             }
    40             sort(m,m+fu,cmp);
    41             //for(int i=0;i<fu;i++)printf("%d ",m[i]);puts("");
    42             for(int i=0;i<(fu/2)*2;i++)ans*=m[i];
    43             printf("%I64d
    ",ans);
    44     }
    45     return 0;
    46 }

    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 -11.

    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.

    Tleq1000T1000, 1leq N leq 10000001N1000000,1 leq M leq 2^{63}1M263​​.

    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代码:
     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
    ",ans);
    35         else puts("-1");
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    【转载】 NumPy之:数据类型对象dtype
    在深度学习的视觉VISION领域数据预处理的魔法常数magic constant、黄金数值的复现: mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225]
    关于Numpy数据类型对象(dtype)使用详解
    【转载】 大端模式和小端模式的区别是什么?
    在使用pytorch官方给出的torchvision中的预训练模型参数时为保证收敛性要求使用原始的数据预处理方式
    【转载】 解决 sudo echo x > 时的 Permission denied错误
    Javascript高级程序设计第二版前三章基本数据等笔记
    冒号课堂§3.4:事件驱动
    理解 JavaScript 闭包
    Browser clientX scrollLeft clientLeft
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4888228.html
Copyright © 2011-2022 走看看