BC第二场
2015-10-17 21:04
495 查看
GT and sequence
Accepts: 385Submissions: 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 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: 146Submissions: 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≤263.
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; }
相关文章推荐
- StoryBoard 关于Segue ----prepareForSegue:sender: 理解
- java网络编程之 UDP的使用
- 好用的编辑框布局控件TdxLayoutControl
- Linux 2.6内核中新的锁机制--RCU
- ThreadPoolExecutor运行原理
- 基于R语言的关联规则实现
- String 类
- iOS应用沙盒机制浅析
- 编写猜数字游戏
- <LeetCode><Easy> 100 Same Tree
- java线程池的简单使用
- Centos6.5 下编译64位 Hadoop 2.2.0
- 信息安全系统设计基础第六周学习总结
- Latex 表格(跨行、跨列、背景加灰)new
- spring IOC源码分析(3)
- N点主机管理系统重置密码方法(在线修改密码)
- 《剑指Offer》小结和博文索引
- iOS之Xcode设置点滴记录(一)
- 设计模式聚合和组合--代码执行
- iframe仿Ajax上传文件