BestCoder Round #54
来源:互联网 发布:七月算法视频pan 编辑:程序博客网 时间:2024/06/02 05:13
传送门
http://acm.hdu.edu.cn/showproblem.php?pid=5427
http://acm.hdu.edu.cn/showproblem.php?pid=5428
http://acm.hdu.edu.cn/showproblem.php?pid=5429
http://acm.hdu.edu.cn/showproblem.php?pid=5430
http://acm.hdu.edu.cn/showproblem.php?pid=5431
T1 A problem of sorting
模拟,没什么说的
var b:array[0..100]of string; a:array[0..100]of longint; i,j,k:longint; t,n:longint;procedure sort(l,r:longint);var i,j,x,y:longint; z:string;begin i:=l; j:=r; x:=a[(l+r) div 2]; repeat while a[i]<x do inc(i); while x<a[j] do dec(j); if not(i>j) then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; z:=b[i]; b[i]:=b[j]; b[j]:=z; inc(i); dec(j); end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r);end;begin readln(t); for j:=1 to t do begin readln(n); for i:=1 to n do begin readln(b[i]); val(copy(b[i],length(b[i])-3,4),a[i]); b[i]:=copy(b[i],1,length(b[i])-5); end; sort(1,n); for i:=n downto 1 do writeln(b[i]); end;end.
T2 The Factor
题目大意
题解
任意一个合数可以写成若干个质数的乘积,所以最小因子的两个因子应为质数,我们对a[i]分解成若干质数,取所有质数中最小的两个乘积即可,不足两个即为无解,输出-1
var sum,prime:array[0..100000]of longint; check:array[0..100000]of boolean; a:array[0..100]of longint; i,j,k:longint; n,t,len,ans:longint;procedure prepare;begin for i:=2 to 100000 do begin if check[i]=false then begin inc(len); prime[len]:=i; end; for j:=1 to len do begin if i*prime[j]>100000 then break; check[i*prime[j]]:=true; if i mod prime[j]=0 then break; end; end;end;procedure apart(x:longint);var i:longint;begin for i:=1 to len do begin if x=1 then break; while x mod prime[i]=0 do begin inc(sum[i]); x:=x div prime[i]; end; end;end;begin prepare; readln(t); for k:=1 to t do begin readln(n); fillchar(sum,sizeof(sum),0); for i:=1 to n do begin read(a[i]); apart(a[i]); end; j:=2; ans:=1; for i:=1 to len do while sum[i]<>0 do if j=0 then break else begin ans:=ans*prime[i]; dec(j); dec(sum[i]); end; if j=0 then writeln(ans) else writeln(-1); end;end.
0 0
- BestCoder Round #54
- BestCoder Round #54
- BestCoder Round #54 (div.2)
- BestCoder Round #54 (div.1)
- BestCoder Round #54 (div.1) ($) Reflect
- BestCoder Round #54 (div.2) 题解
- BestCoder Round #3 BestCoder Sequence
- bestcoder round #1
- BestCoder round #1
- BestCoder Round #1
- 【索引】BestCoder Round #2
- BestCoder Round #2
- 【索引】BestCoder Round #3
- BestCoder Round #3
- BestCoder Round #3 小记
- BestCoder Round #4 题解
- BestCoder Round #6
- BestCoder Round #8
- Exynos4412 Andriod4.4 源码编译生成SDK
- Comet:基于 HTTP 长连接的“服务器推”技术
- 通达OA破解版下载|通达OA2015破解版 可用|通达oa2015破解补丁
- 网络流之最大流(关于poj1273)
- Hibernate批量操作(JDBC批量操作)
- BestCoder Round #54
- Hibernate二级缓存 ---- 最佳实践
- Codeforces Gym 100345H Settling the Universe Up Bitset+倒推
- 云购吧 使用说明文档
- Java Convert String & Int
- 浅谈Activity的启动模式
- Hibernate二级缓存 ---- 入门示例
- ICPC 6834 Shopping
- windows下成功编译Cairo,Compiling Cairo for Windows