Noj - 在线强化训练1

时间:2023-03-09 09:03:59
Noj - 在线强化训练1
  1445 A 求n个整数的和
  1564 B 判断一个数是否是完全数
  1011 C 判素数(Prime number)
  1566 D 输入一组整数,找出最小值
  1200 E 判断三角形是否为直角三角形
  1508 F 袋子里有多少个球(一般情况)
  1139 G 叙拉古猜想
  1135 H 阿姆斯特朗数(Armstrong number)
  1031 I 求阶乘和(the sum of Factorial)
  1402 J 数字根(Digital Roots)
  1567 K 拆分数字并从低位到高位输出
  1565 L 十进制数转二进制从低位到高位输出
Problem A
求n个整数的和
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:

先输入一个正整数n,再输入n个整数,求它们的和。
输入:

先输入一个正整数n,再输入n个正整数,

输出:

输出它们的和

输入样例:

输出样例:

Problem A 求n个整数的和

#include <iostream>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        ;
        int temp;
        ; i<n; i++)
        {
            cin>>temp;
            sum += temp;
        }
        cout<<sum<<endl;
    }

    ;
}

代码A

Problem B
判断一个数是否是完全数
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:

如果一个大于2的整数的不包含它自身的约数之和恰好等于它本身,则称其为完全数。如:=++,所以,6是个完全数。
Perfect number is defined as follows:the sum of it’s common divisor which does not includes it’s maximum equals itself.

输入:

输入一个大于2的整数n,

输出:

编程判断n是不是完全数,如果是输出“Yes”,否则输出“No”。

输入样例:

输出样例:

Yes

Problem B 判断一个数是否是完全数

#include <iostream>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        ;
        ; i<n; i++)
        {
            )
                sum += i;
        }
        if(sum == n)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }

    ;
}

代码B

Problem C
判素数(Prime number)
时限:100ms 内存限制:10000K 总时限:1000ms
描述:

给出一个数n(<=n<=),判定它是否为素数。
素数:一个大于等于2的数,除了1和它本身,再没有其他的整数能将其整除的数叫素数。
Input a number n(<=n<=), judge if it is a prime number.

输入:

从标准输入输入一个整数。
Input a number n(<=n<=)

输出:

若给定数为素数,向标准输出输出“Yes”,否则,输出“No”。
If the number is a prime, output “Yes”. Otherwise, output “No”.

输入样例:

输出样例:

Yes

Problem C 判素数(Prime number)

#include <iostream>
#include<stdio.h>
using namespace std;

int main()
{
    int n;

    while(cin>>n)
    {
        ;
        ; i<=n/; i++)
        {
            )
            {
                flag = ;
                break;
            }
        }
        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    ;
}

代码C

Problem D
输入一组整数,找出最小值
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:

先输入一个正整数n,然后输入n个整数,输出其最小值。

输入:

先输入一个正整数n,然后输入n个整数。

输出:

输出其最小值(最后输出一个回车)。

输入样例:

输出样例:

Problem D 输入一组整数,找出最小值

 #include <iostream>
 #include<stdio.h>
 using namespace std;

 int main()
 {
     int n;
     while(cin>>n)
     {
         ;
         int temp;
         ; i<n; ++i)
         {
             cin>>temp;
             if(temp <= min)
                 min = temp;
         }
         cout<<min<<endl;
     }
     ;
 }

代码D

Problem E
判断三角形是否为直角三角形
时限:100ms 内存限制:10000K 总时限:1000ms
描述:

给定平面直角坐标系中的三个点的坐标,判断是否能构成直角三角形。

输入:

三个点的坐标,数据都在-100000到100000之间。

输出:

一个整数,当可以构成直角三角形的时候输出1,否则输出0。

输入样例:

输出样例:

Problem E 判断三角形是否为直角三角形

 #include <iostream>
 #include<stdio.h>
 using namespace std;

 int main()
 {
     ];
     ; i<; i++)
     {
         cin>>p[i];
     }
     double a,b,c;
     a = (p[]-p[])*(p[]-p[]) + (p[]-p[])*(p[]-p[]);
     b = (p[]-p[])*(p[]-p[]) + (p[]-p[])*(p[]-p[]);
     c = (p[]-p[])*(p[]-p[]) + (p[]-p[])*(p[]-p[]);
     if(a+b==c || a+c==b || b+c == a)
         cout<<<<endl;
     else
         cout<<<<endl;

     ;
 }

代码E

Problem F
袋子里有多少个球(一般情况)
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:

袋子里有若干个球的问题,聪明的佳佳很快就算出来了,但是他想写一个程序解决这个问题,并想把问题扩展到一般情况:每次拿出其中的一半再放回去一个球,一共这样做了n次,袋子里还有m个球。问原来袋子中有多少个球?

输入:

输入两个正整数n和m,

输出:

袋子里原来有多少个球

输入样例:

输出样例:

Problem F 袋子里有多少个球(一般情况)

 #include <iostream>
 #include<stdio.h>
 using namespace std;

 int main()
 {

     int n, m;
     cin>>n;
     cin>>m;
     ; i<n; i++)
     {
         m = (m-) * ;
     }
     cout<<m<<endl;
     ;
 }

代码F

Problem G
叙拉古猜想
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:

叙拉古猜想又称科拉兹猜想、哈塞猜想、3n+1猜想、乌拉姆猜想或角谷猜想,是指对于每一个大于1的正整数,如果它是奇数,则将其乘3加1,如果它是偶数,则将除以2,如此循环,最终将得到1。
Syracuse conjecture also known  conjecture the Ulam conjecture or angle Valley conjecture, means ,  and plus1, , and so on, will eventually give .

输入:

输入数据包含一个整数N(<N<=)。
Input a positive integer.

输出:

输出数据包含从这个整数到1的按照叙拉古猜想变换的序列,每行一个数字。
Output the sequence in accordance with the Syracuse guess, one per line figures.

输入样例:

输出样例:

Problem G 叙拉古猜想

 #include <iostream>
 #include<stdio.h>
 using namespace std;

 int main()
 {

     int N;
     while(cin>>N)
     {
         cout<<N<<endl;
         )
         {
              == )
                 N /= ;
             else
                 N = N* + ;
             cout<<N<<endl;
         }
     }
 }

代码G

Problem H
阿姆斯特朗数(Armstrong number)
时限:1000ms 内存限制:10000K 总时限:1000ms
描述:

阿姆斯特朗数又称水仙花数,是指一种三位数,其各个数字之立方和等于该数。
Armstrong number which is also called Daffodils number is a three-figure number,and the sum of the number of it’s respective positions equals itself.
For example  = ** + ** + ** 

输入:

本题无输入
None

输出:

升序输出所有阿姆斯特朗数,每个数字占一行。
Output all Armstrong number in ascending order and every integer occupies a line only.

输入样例:

无None
输出样例:

无None

Problem H 阿姆斯特朗数(Armstrong number)

 #include <iostream>
 #include<stdio.h>
 #include<math.h>
 using namespace std;

 int main()
 {
     int a,b,c;
     ; i<; i++)
     {
         a = i/;
         b = (i-a*) / ;
         c = i-a*-b*;
         if(i == a*a*a + b*b*b + c*c*c)
             cout<<i<<endl;
     }
 }

代码H

Problem I
求阶乘和(the sum of Factorial)
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:

给你一个正整数n,请你求1到n的阶乘的和,并输出最后结果
如给你5 , 即计算 !+!+!+!+!
Input a positive integer n,and calculate the sum of n!.For example,n  and calculate the following formula:
!+!+!+!+!

输入:

一个正整数n
a positive integer n.

输出:

求得的阶乘和
The sum of n!

输入样例:

输出样例:

Problem I 求阶乘和(the sum of Factorial)

 #include <iostream>
 using namespace std;

 int main()
 {
     int n;
     while(cin>>n)
     {
         ;
         int temp;
         ; i<=n; i++)
         {
             temp = ;
             ; j<=i; j++)
                 temp *= j;
             sum += temp;
         }
         cout<<sum<<endl;
     }
 }

代码I

Problem J
数字根(Digital Roots)
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:

一个正整数的数字根是指该数字各位数字之和,如果和是一个个位数,那么这个数字就是它的数字根,如果和是个两位或多于两位的数字,那么就继续求和直到得到个位数。
例如:数字24,把2和4相加,得到6,那么6就是24的数字根;又比如数字39,把数字3和9相加,得到12,因为12时是两位数,所以继续把1和2相加,得到3,于是3就是39的数字根。
The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.
For example, consider the positive integer . Adding the  and the  yields a value of . Since   . Now consider the positive integer . Adding the  and the  yields . Since   and the  yeilds , a single digit and also the digital root of .

输入:

输入一个正整数,
input a positive integer,

输出:

输出它的数字根。
Output its digital root.

输入样例:

输出样例:

Problem J 数字根(Digital Roots)

 #include <iostream>
 using namespace std;

 int main()
 {
     int n;
     while(cin>>n)
     {
         int temp;
         ;
         while(n)
         {
             temp = n%;
             n /= ;
             sum += temp;
         }
         )
             cout<<sum<<endl;
         else
         {
             int temp2,temp3;
             )
             {
                 temp2 = sum;
                 sum = ;
                 while(temp2)
                 {
                     temp3 = temp2%;
                     temp2 /= ;
                     sum += temp3;
                 }
             }
             cout<<sum<<endl;
         }
     }
 }

代码J

Problem K
拆分数字并从低位到高位输出
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:

输入一个正整数,将其各个位上的数字按从低位到高位的顺序单独输出,每个数字占一行。提示可用两种除法/和%,用于整数时第一种除法的结果是商的整数部分,第二种除法的结果是余数,例如:/=,%=)

输入:

一个正整数。

输出:

将其各个位上的数字按从低位到高位的顺序单独输出,每个数字占一行。

输入样例:

输出样例:

Problem K 拆分数字并从低位到高位输出

 #include <iostream>
 using namespace std;
 void swap(int *p,int *p2);
 int main()
 {
     int n;
     ];
     while(cin>>n)
     {
         ;
         while(n)
         {
             num[i] = n % ;
             n /= ;
             i++;
         }
         ; j<i; j++)
         {
             cout<<num[j]<<endl;
         }
     }
 }

代码K

Problem L
十进制数转二进制从低位到高位输出
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:

输入一个十进制数,把它转成二进制数后,从低位到高位输出。

输入:

一个十进制数n。

输出:

把n转化为二进制数以后,从地位到高位输出(每个数字占一行)。

输入样例:

输出样例:

Problem L 十进制数转二进制从低位到高位输出

 #include <iostream>
 using namespace std;
 void swap(int *p,int *p2);
 int main()
 {
     int n;
     while(cin>>n)
     {
         ];
         ;
         while(n)
         {
             b[i] = n % ;
             n /= ;
             i++;
         }
         ; j<i; j++)
         {
             cout<<b[j]<<endl;
         }
     }
 }

代码L