BestCoder Round #54

Source: Internet
Author: User

BestCoder Round #54

 

HDU No.5427 A problem of sorting (simple sorting)

Code:

 

/** Problem: HDU No.5427 * Running time: 0 MS * Complier: C ++ * Author: javaherongwei * Create Time: Sunday */# 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 (analog, select The minimum two factors)

Code:

 

 

/** Problem: HDU No.5428 * Running time: 0 MS * Complier: C ++ * Author: javaherongwei * Create Time: Sunday */# include
 
  
Using namespace std; typedef long LL; const int N = 1e6 + 10; int num [N]; int n, m, ll; void get (int) {// 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 (judge whether a sequence is an equal-ratio sequence + java simulation)

Code:

 

/** Problem: HDU No.5429 * Running time: 380 MS * Complier: JAVA * Author: javaherongwei * Create Time: Sunday */import java. util. *; import java. io. *; import java. math. *; public class Main {public static void main (String args []) {using cin = new using (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 (geometric quandary) [ideas + Questions]

Code:

 

/** Problem: HDU No.5430 * Running time: 374 MS * Complier: C ++ * Author: javaherongwei * Create Time: Sunday * // 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
       
        
# Define deusing 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 ;}
       
      
     
    
   


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.