Noj - 在线强化训练1

Posted tanrong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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个正整数,

输出:

输出它们的和

输入样例:

3 12 18 33
输出样例:

63
Problem A 求n个整数的和
技术分享图片
#include <iostream>
using namespace std;

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

    return 0;
}
代码A

 

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


如果一个大于2的整数的不包含它自身的约数之和恰好等于它本身,则称其为完全数。如:6123,所以,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”。

输入样例:


28
输出样例:


Yes
Problem B 判断一个数是否是完全数
技术分享图片
#include <iostream>
using namespace std;

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

    return 0;
}
代码B

 

技术分享图片
Problem C
判素数(Prime number)
时限:100ms 内存限制:10000K 总时限:1000ms
描述:


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

输入:


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

输出:


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

输入样例:


7
输出样例:


Yes
Problem C 判素数(Prime number)
技术分享图片
#include <iostream>
#include<stdio.h>
using namespace std;

int main()
{
    int n;

    while(cin>>n)
    {
        int flag=1;
        for(int i=2; i<=n/2; i++)
        {
            if(n % i == 0)
            {
                flag = 0;
                break;
            }
        }
        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}
代码C
 
技术分享图片
Problem D
输入一组整数,找出最小值
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:


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

输入:


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

输出:


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

输入样例:


522 67 8 882 300
输出样例:


8
Problem D 输入一组整数,找出最小值
技术分享图片
 1 #include <iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int n;
 8     while(cin>>n)
 9     {
10         int min = 10000000;
11         int temp;
12         for(int i=0; i<n; ++i)
13         {
14             cin>>temp;
15             if(temp <= min)
16                 min = temp;
17         }
18         cout<<min<<endl;
19     }
20     return 0;
21 }
代码D

 

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


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

输入:


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

输出:


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

输入样例:


0 03 00 8
输出样例:


1
Problem E 判断三角形是否为直角三角形
技术分享图片
 1 #include <iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     double p[7];
 8     for(int i=1; i<7; i++)
 9     {
10         cin>>p[i];
11     }
12     double a,b,c;
13     a = (p[4]-p[2])*(p[4]-p[2]) + (p[3]-p[1])*(p[3]-p[1]);
14     b = (p[6]-p[2])*(p[6]-p[2]) + (p[5]-p[1])*(p[5]-p[1]);
15     c = (p[6]-p[4])*(p[6]-p[4]) + (p[5]-p[3])*(p[5]-p[3]);
16     if(a+b==c || a+c==b || b+c == a)
17         cout<<1<<endl;
18     else
19         cout<<0<<endl;
20 
21     return 0;
22 }
代码E

 

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


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

输入:


输入两个正整数n和m,

输出:


袋子里原来有多少个球

输入样例:


1 3
输出样例:


4
Problem F 袋子里有多少个球(一般情况)
技术分享图片
 1 #include <iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7 
 8     int n, m;
 9     cin>>n;
10     cin>>m;
11     for(int i=0; i<n; i++)
12     {
13         m = (m-1) * 2;
14     }
15     cout<<m<<endl;
16     return 0;
17 }
代码F

 

技术分享图片
Problem G
叙拉古猜想
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:


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

输入:


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

输出:


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

输入样例:


3
输出样例:


3105168421
Problem G 叙拉古猜想
技术分享图片
 1 #include <iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7 
 8     int N;
 9     while(cin>>N)
10     {
11         cout<<N<<endl;
12         while(N != 1)
13         {
14             if(N%2 == 0)
15                 N /= 2;
16             else
17                 N = N*3 + 1;
18             cout<<N<<endl;
19         }
20     }
21 }
代码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 153 = 1*1*1 + 5*5*5 + 3*3*3 

输入:


本题无输入
None

输出:


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

输入样例:


无None
输出样例:


无None
Problem H 阿姆斯特朗数(Armstrong number)
技术分享图片
 1 #include <iostream>
 2 #include<stdio.h>
 3 #include<math.h>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int a,b,c;
 9     for(int i=100; i<1000; i++)
10     {
11         a = i/100;
12         b = (i-a*100) / 10;
13         c = i-a*100-b*10;
14         if(i == a*a*a + b*b*b + c*c*c)
15             cout<<i<<endl;
16     }
17 }
代码H

 

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


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

输入:


一个正整数n
a positive integer n.

输出:


求得的阶乘和
The sum of n!

输入样例:


5
输出样例:


153
Problem I 求阶乘和(the sum of Factorial)
技术分享图片
 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int n;
 7     while(cin>>n)
 8     {
 9         int sum = 0;
10         int temp;
11         for(int i=1; i<=n; i++)
12         {
13             temp = 1;
14             for(int j=1; j<=i; j++)
15                 temp *= j;
16             sum += temp;
17         }
18         cout<<sum<<endl;
19     }
20 }
代码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 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.

输入:


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

输出:


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

输入样例:


39
输出样例:


3
Problem J 数字根(Digital Roots)
技术分享图片
 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int n;
 7     while(cin>>n)
 8     {
 9         int temp;
10         int sum = 0;
11         while(n)
12         {
13             temp = n%10;
14             n /= 10;
15             sum += temp;
16         }
17         if(sum < 10)
18             cout<<sum<<endl;
19         else
20         {
21             int temp2,temp3;
22             while(sum >= 10)
23             {
24                 temp2 = sum;
25                 sum = 0;
26                 while(temp2)
27                 {
28                     temp3 = temp2%10;
29                     temp2 /= 10;
30                     sum += temp3;
31                 }
32             }
33             cout<<sum<<endl;
34         }
35     }
36 }
代码J

 

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


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

输入:


一个正整数。


输出:


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


输入样例:


12345
输出样例:


54321
Problem K 拆分数字并从低位到高位输出
技术分享图片
 1 #include <iostream>
 2 using namespace std;
 3 void swap(int *p,int *p2);
 4 int main()
 5 {
 6     int n;
 7     int num[10];
 8     while(cin>>n)
 9     {
10         int i = 0;
11         while(n)
12         {
13             num[i] = n % 10;
14             n /= 10;
15             i++;
16         }
17         for(int j=0; j<i; j++)
18         {
19             cout<<num[j]<<endl;
20         }
21     }
22 }
代码K

 

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


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

输入:


一个十进制数n。

输出:


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

输入样例:


13
输出样例:


1011
Problem L 十进制数转二进制从低位到高位输出
技术分享图片
 1 #include <iostream>
 2 using namespace std;
 3 void swap(int *p,int *p2);
 4 int main()
 5 {
 6     int n;
 7     while(cin>>n)
 8     {
 9         int b[100];
10         int i = 0;
11         while(n)
12         {
13             b[i] = n % 2;
14             n /= 2;
15             i++;
16         }
17         for(int j=0; j<i; j++)
18         {
19             cout<<b[j]<<endl;
20         }
21     }
22 }
代码L

 

以上是关于Noj - 在线强化训练1的主要内容,如果未能解决你的问题,请参考以下文章

离线强化训练

使用强化学习训练神经网络

强化学习系列12:使用julia训练深度强化模型

1Python进阶强化训练之装饰器使用技巧进阶

强化学习基于tensorflow2.x 的 PPO2(离散动作情况) 训练 CartPole-v1

循环控制强化训练