Day11:打卡代码题(31-33) + 英语翻译
特别注意n的类型需要设置为long long类型,int类型可能会超过范围。代码int main()double x;cin >> x;int k = 1;//防止分母太大,爆intn *= k;k ++;//分母加一cnt ++;//项数加一return 0;
题目31:素数
问题描述
判断一个数是不是素数
输入说明
第一行为N
下面N行,每行一个数字n
输出说明
判断n是不是素数,是就输出yes,否则输出no
输入范例
3
897
23
97
输出范例
no
yes
yes
代码
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int n;
cin >> n;
int k = 0;
while(n --)
{
int x;
cin >> x;
int flag = 0;
if(x == 1) flag = 1;
for(int i = 2; i <= sqrt(x); i ++)
{
if(x % i == 0)
{
flag = 1;
break;
}
}
if(k) cout << endl;
if(flag) cout << "no";
else cout << "yes";
k = 1;
}
return 0;
}
题目32:计算e
问题描述
利用公式e=1+ 1/1! + 1/2! + 1/3! + ... + 1/n!,编程计算e的近似值,直到最后一项的绝对值小于threshold(该项不包括在结果内),输出e的值并统计累加的项数。
输入说明
输入一个实数threshold,表示累加的阈值,数列中最后一项的值大于等于该阈值。Threshold最小可为1e-10。
输出说明
输出一个实数表示e的值,保留6位小数,并输出一个整数,表示累加的项数。两个数字之间用一个空格分隔,在行首和行尾没有多余的空格。
输入范例
0.00001
输出范例
2.718279 9
个人总结
特别注意n的类型需要设置为long long类型,int类型可能会超过范围。
代码
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
int main()
{
double x;
cin >> x;
double sum = 0;
int cnt = 0;
int k = 1;
long long n = 1;//防止分母太大,爆int
while(1.0 / n >= x)
{
sum += 1.0 / n;
n *= k;
k ++;//分母加一
cnt ++;//项数加一
}
cout << fixed << setprecision(6) << sum;
cout << ' ' << cnt;
return 0;
}
题目33:数字之和
问题描述
输入一个正整数,求这个正整数的各位数字之和。
输入说明
你的程序需要从标准输入设备(通常为键盘)中读入多组测试数据。每组测试数据为正整数,每行一个N,N小于20000。
输出说明
对每组测试数据,你的程序需要向标准输出文件(通常为启动该程序的文本终端)依次输出一组对应的答案:输出为它的各位数字之和,所有数据前后没有多余的空行,两组数据之间也没有多余的空行。
输入范例
10
99
输出范例
1
18
代码
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
int flag = 0;
while(cin >> n)
{
int sum = 0;
if(flag) cout << endl;
while(n > 0)
{
sum += n % 10;
n /= 10;
}
cout << sum;
flag = 1;
}
return 0;
}
英语翻译
II. Research Methodologies 研究方法
To appreciate the field of artificial intelligence, it is helpful to understand that it is being pursued along two paths. One is the engineering track in which researchers are trying to develop systems that exhibit intelligent behavior. The other is a theoretical track in which researchers are trying to develop a computational understanding of animal—especially human—intelligence. This dichotomy is clarified by considering the manner in which the two tracks are pursued. The engineering approach leads to a performance-oriented methodology because the underlying goal is to produce a product that meets certain performance goals. The theoretical approach leads to a simulation-oriented methodology because the underlying goal is to expand our understanding of intelligence and thus the emphasis is on the underlying process rather than the exterior performance.
要深入理解人工智能领域,沿着这俩条路径是非常有帮助的。一种是研究人员正致力于开发能展现智能行为的系统的工程研究方向。另一种则是研究人员正努力开发的一种能使用计算理解动物(特别是人类)智能的理论研究方向。这种二分法是通过考虑两种方向的研究的方法来阐明的。工程研究方法衍生出以性能为主导的方法,因为开发一个符合实际性能指标的产品才是最根本的目标。理论研究方法则衍生出以仿真为主导的方法,因为拓宽我们对智能的理解才是最根本的目标,所以相比外在表现,内在过程才是重点。
dichotomy /dai'kɔtəmi/ n. 一分成二;二分法
simulation /ˌsimju'lei∫ən/ n. 模拟,仿真
As an example, consider the fields of natural language processing and linguistics. These fields are closely related and benefit from research in each other, yet the underlying goals are different. Linguists are interested in learning how humans process language and thus tend toward more theoretical pursuits. Researchers in the field of natural language processing are interested in developing machines that can manipulate natural language and therefore lean in the engineering direction. Thus, linguists operate in simulation-oriented mode—building systems whose goals are to test theories. In contrast, researchers in natural language processing operate in performance-oriented mode—building systems to perform tasks. Systems produced in this latter mode (such as document translators and systems by which machines respond to verbal commands) rely heavily on knowledge gained by linguists but often apply "shortcuts" that happen to work in the restricted environment of the particular system.
例如,考虑自然语言处理和语言学的领域。这些领域紧密关联,并且在研究上相互受益,但在根本目标上却是大相径庭的。语言学家对人们如何处理语言很感兴趣,因此更加倾向于理论研究。在自然语言处理领域的研究者对于开发能处理自然语言的机器很感兴趣,所以更倾向于工程方向。因此,语言学家采用面向仿真的模式,构建能够验证理论的系统。相反,在自然语言处理领域的研究人员采用面向性能模式,构建解决具体任务的系统。在后面构建的这种系统中(例如文档翻译器和能让机器回应语音指令的系统)极具依赖从语言学家那里获取的知识,但经常采用只在特定的系统受限环境才能发挥作用的“捷径”。
linguist /'liŋɡwist/ n. 语言学家
pursuit /pə'sjuːt/ n. 追求;追赶
As an elementary example, consider the task of developing a shell for an operating system that receives instructions from the outside world through verbal English commands. In this case, the shell (an agent) does not need to worry about the entire English language. More precisely, the shell does not need to distinguish between the various meanings of the word copy.(Is it a noun or a verb? Should it carry the connotation of plagiarism?) Instead, the shell needs merely to distinguish the word copy from other commands such as rename and delete. Thus the shell could perform its task just by matching its inputs to predetermined audio patterns. The performance of such a system may be satisfactory to an engineer, but the way it is obtained would not be aesthetically pleasing to a theoretician.
举一个基本的例子,考虑为操作系统开发命令行外壳,它通过外界的英语语音指令来接收指令。在这种情况下,这个外壳(一个智能体)不需要担心完整的英语语言体系。更准确地说,这个外壳不需要区分copy这个词的多种意思。(它是一个名词还是动词?它应该包含“抄袭”这个引申义吗?相反,这个外壳仅仅只需要把copy与例如rename和delete的其他指令区分开。所以这个壳能仅仅通过匹配它的输入与预定的音频模式来完成任务。这样的一个系统的表现可能能满足一个工程师,但实现的方式对于理论研究者来说可能不是很赏心悦目。
connotation /ˌkɔnəu'tei∫ən/ n. 内涵(意义),含义
plagiarism /'pleiʤiərizəm/ n. 剽窃,抄袭
aesthetical /iːs'θetikəl/ a. 美学的;审美的
theoretician /ˌθiəri'ti∫ən/ n. 理论家
更多推荐



所有评论(0)