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 星期日 */ #includeusing 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; }
/* * Problem: HDU No.5428 * Running time: 0MS * Complier: C++ * Author: javaherongwei * Create Time: 12:13 2015/9/6 星期日 */ #includeusing 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 ,(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 1000005
int 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
#include
using 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
,ans);
}
return 0;
}