问题九十七,最小公倍数最大问题
分类:计算机网络

HDU 5166,hdu5166

HDU 4627(最小公倍数最大问题),hdu4627

HDU 5166

[plain]  Give you an integer; your task is to output its reverse number. Here, reverse number is defined as follows: 

HDU 5166

                       HDU 4627 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  

Description

There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number. 
Given an integer n(2 <= n <= 10 9美高梅网址 ,).We should find a pair of positive integer a, b so that a + b = n and [a, b] is as large as possible. [a, b] denote the least common multiplier of a, b.  

Input

The first line contains integer T(1<= T<= 10000),denote the number of the test cases. 
For each test cases,the first line contains an integer n.  

Output

For each test cases, print the maximum [a,b] in a line.  

Sample Input

3 2 3 4  

Sample Output

1 2 3   此题的话,因为一个数n由两个正整数a+b得来,所以可以先确定a和b的范围,是从1到n/2   因为从n/2+1到n,是和前半部分重复,不用计算   然后,就用辗转相除法,a,b互质,输出最大的 LCM(a, b),即a,b的最小公倍数最大。  注意:这种算法易懂,但是很容易超时,自己做的时候就是  #include <stdio.h>
int main()
{
int a,b,c;
int max,min,t1,t2;
int i,n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
max=0;
for(i=1;i<=n/2;i++)
{
a=i;
b=n-i;
a>b?t1=a:t1=b;
t2=n-t1;
while(t2)
{
c=t1%t2;
t1=t2;
t2=c;
}
min=a*b/t1;
if(min>max)
max=min;
}
printf("%dn",max);
}
return 0;

 

另外还有一种,这是一种奇偶求法,很简单巧妙,经某ACM大神指点得知

#include <stdio.h>

int main()
{
int n,T;
long long max;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
max=0;
if (n==2) printf("1n");
else
{
if (n%2==0)
{
max=n/2;
if (max%2==0) max=(max+1)
(max-1);
else max=(max+2)*(max-2);
}
else
{
max=n/2;
max=max*(max+1);
}
printf("%I64dn",max);
}
}
return 0;
}*

 

4627(最小公倍数最大问题),hdu4627 HDU 4627 Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d %I64u Description There are many unsolvable problem in...

Time Limit:1000MSMemory Limit:65536KB64bit IO Format:%I64d & %I64u

Description

There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose.

Input

There is a number shows there are test cases below. (0<=T <=10)
For each test case , the first line contains a integers , which means thenumber of numbers the permutation has. In following a line , there are $n$distinct postive integers.(1 <=n <=1,000)

Output

For each caseoutput two numbers , small number first.

Sample Input

2

3

3 4 5

1

1

Sample Output

1 2

2 3

题解:找出一个数列中缺的两个数(这两个数要为最小的两个数)。

注意:利用bool函数把数组中所有数全部返回0

#include<stdio.h>  int main()  {      int T,i;     scanf("%d",&T);     while(T--)      {          int count,t=0,j[2];;          scanf("%d",&count);         bool flag[1005]={  false  };        for( i=1;i<=count;i++)         {             int tem;             scanf("%d",&tem);             flag[tem]=true;//每输入一个数s,便给第s个赋值为1         }                           for(i=1;i<=count+2;i++)         {             if(flag[i]==0)//如果有为0的出现,则为缺失的数             {                 j[t++]=i;                 }        }         printf("%d %dn",j[0],j[1]);              }     return 0; }

多多交流~

  1. The reverse number of a positive integer ending without 0 is general reverse, for example, reverse (12) = 21; 
  2. The reverse number of a negative integer is negative, for example, reverse (-12) = -21; 
  3. The reverse number of an integer ending with 0 is described as example, reverse (1200) = 2100.  
     
    Input 
     
    Input file contains multiple test cases. There is a positive integer n (n<100) in the first line, which means the number of test cases, and then n 32-bit integers follow. 
     
    Output 
     
    For each test case, you should output its reverse number, one case per line. 
     
    Sample Input 
     
     

    12 
    -12 
    1200 
     
    Sample Output 
     
     
    21 
    -21 
    2100 

Time Limit:1000MS  Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose.

 

Input

There is a number (T) shows there are (T) test cases below. ($T leq 10$) 
For each test case , the first line contains a integers (n) , which means the number of numbers the permutation has. In following a line , there are $n$ distinct postive integers.($1 leq n leq 1,000$)

 

Output

For each case output two numbers , small number first.

 

Sample Input

2

3

3 4 5

1

1

 

Sample Output

1 2

2 3

 题解:找出一个数列中缺的两个数(这两个数要为最小的两个数)。

  注意:利用bool函数把数组中所有数全部返回0

 

#include<stdio.h>

*int main()
{
  int T,i;
  scanf("%d",&T);
  while(T--)
{
  int count,t=0,j[2];;
  scanf("%d",&count);
  bool flag[1005]={ false };
    for( i=1;i<=count;i++)
  {
    int s;
    scanf("%d",&s);
    flag[s]=true;//每输入一个数s,便给第s个赋值为1
  }

  for(i=1;i<=count+2;i++)
{
    if(flag[i]==0)
  {
    j[t++]=i; //如果有为0的出现,则为缺失的数
  }
}
  printf("%d %dn",j[0],j[1]);

}
  return 0;
}*

多多交流~ 

5166,hdu5166 HDU 5166 Time Limit:1000MSMemory Limit:65536KB64bit IO Format:%I64d %I64u Description There is a permutation without two numbers in it, and now you know what num...

Give you an integer; your task is to output its reverse number. Here, reverse number is defined as follows:

  1. The reverse number of a positive integer ending without 0 is general reverse, for example, reverse (12) = 21;
  2. The reverse number of a negative integer is negative, for example, reverse (-12) = -21;
  3. The reverse number of an integer ending with 0 is described as example, reverse (1200) = 2100.

Input

Input file contains multiple test cases. There is a positive integer n (n<100) in the first line, which means the number of test cases, and then n 32-bit integers follow.

Output

For each test case, you should output its reverse number, one case per line.

Sample Input

3
12
-12
1200

Sample Output

21
-21
2100
[plain]  <PRE class=plain name="code">#include <stdio.h> 
 
int main() 

    int i; 
    int j; 
    int n; 
    int tab;                        //标记末尾是否有零 
    int num; 
    int flag;                      //标记是否是正负数   
    int count; 
    int array[100];                 //存储各位的数值 
 
    scanf("%d", &n); 
    while(n--) 
    {   
        scanf("%d", &num); 
         
        j=0; 
        tab=1;                //假设末尾有零 
        flag=1;               // 正数为1 
        count=0; 
        if(num<0 ) 
        { 
            flag=0;            //负数 
            num=-1* num;          
        } 
 
        while(num) 
        { 
            if(num%10==0 && tab!=0)     
            { 
               count++;        //计算零的个数 
            } 
            else 
            { 
               array[j++]=num%10; 
               tab=0;      
            } 
            num/=10; 
        } 
 
        if(flag==0)      
        { 
            printf("-"); 
        } 
 
        for(i=0; i<j; i++) 
        { 
             printf("%d", array[i]); 
        } 
         
        for(i=0; i<count; i++)         //打印末尾零的个数 
        { 
            printf("0"); 
        } 
        if(n>0)       
        { 
            printf("n"); 
        } 
    } 
 
    return 0; 

</PRE><BR> 
<BR> 
<PRE></PRE> 
<P>    </P> 
<PRE></PRE> 
<PRE></PRE> 

] Give you an integer; your task is to output its reverse number. Here, reverse number is defined as follows:

  1. The reverse number of a positive integer ending without 0 is...

本文由美高梅网址发布于计算机网络,转载请注明出处:问题九十七,最小公倍数最大问题

上一篇:没有了 下一篇:没有了
猜你喜欢
热门排行
精彩图文