BestCoder Round #54

网友投稿 563 2022-10-25

BestCoder Round #54

BestCoder Round #54

【题目链接】:​​click here~~​​

HDU No.5427  A problem of sorting (简单排序)

代码

/** Problem: HDU No.5427* Running time: 0MS* Complier: C++* Author: javaherongwei* Create Time: 11:48 2015/9/6 星期日*/#include using namespace std;const int N=105;char s1[N][N];int a[N];int b[N];bool cmp(const int &x, const int &y){ return a[x]>a[y];}char s2[N*10];int main(){ int k,m,n; int t;scanf("%d",&t); while(t--){ scanf("%d",&n);getchar(); for(int i=1; i<=n; i++){ gets(s2); int len=strlen(s2); int id=len; while(s2[id]==' ') id--;int ix = id; while(s2[ix]!=' ') ix--;ix++; int num = sscanf(s2+ix, "%d",&k); // return the return value a[i]=k; ix--; s2[ix] = 0; strcpy(s1[i],s2); b[i]=i; } sort(b+1, b+1+n, cmp); for(int i=1; i<=n; i++) puts(s1[b[i]]); } return 0;}

HDU No.5428   The Factor (模拟,选择最小的两个因子)

代码:

/** Problem: HDU No.5428* Running time: 0MS* Complier: C++* Author: javaherongwei* Create Time: 12:13 2015/9/6 星期日*/#include using namespace std;typedef long long LL;const int N=1e6+10;int num[N];int n,m,ll;void get(int a){ // get the factor for(int i=2; (LL)i*i<=(LL)a; ++i){ while(a%i==0){ num[++ll]=i; a/=i; } } if(a>1) num[++ll]=a;}int main(){ int t;scanf("%d",&t); while(t--){ scanf("%d",&n); ll=0; for(int i=1; i<=n; ++i){ scanf("%d",&m);get(m); } if(ll<2){ puts("-1"); continue; } sort(num+1,num+1+ll); printf("%I64d\n",(LL)num[1]*num[2]); // get the min factor } return 0;}

HDU 5429  Geometric Progression (判断一个序列是否是等比序列 +java模拟)

代码:

/** Problem: HDU No.5429* Running time: 380MS* Complier: JAVA* Author: javaherongwei* Create Time: 17:05 2015/9/6 星期日*/import java.util.*;import java.io.*;import java.math.*;public class Main { public static void main(String args[]) { Scanner cin=new Scanner(new BufferedInputStream(System.in)); int t=cin.nextInt(); BigInteger fac[]= new BigInteger[105]; BigInteger f1,f2; while(t-->0) { int n=cin.nextInt(); int sum=0; for(int i=0; i

HDU 5430: Reflect(几何趣题)

【思路+题解】

代码:

/** Problem: HDU No.5430* Running time: 374MS* Complier: C++* Author: javaherongwei* Create Time: 17:05 2015/9/6 星期日*///solve one: #include using namespace std;#define N 1000005int dp[1000005];int phi[N];void get() // get the prime factor { int i,j; memset(phi,0,sizeof(phi)); phi[1]=1; for(i=2;i>m) { while(m--) { cin>>n; cout<#include#include#includeusing namespace std;int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); int ans=0; for(int i=1; i<=n; i++) if(gcd(i,n+1)==1) ans++; printf("%d\n",ans); } return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【常见面试题总结之C++中sizeof问题】
下一篇:spring boot线上日志级别动态调整的配置步骤
相关文章

 发表评论

暂时没有评论,来抢沙发吧~