欢迎光临
我们一直在努力

素数、计算e、数字之和——Day11

 问题1:

        判断一个数是不是素数(素数)

输入、输出要求:

        第一行为N,下面N行,每行一个数字n

        判断n是不是素数,是就输出yes,否则输出no

输入输出示例:

个人总结:

        1.本题注意输入输出格式

实现代码如下示:

#include<iostream>
using namespace std;
int isPr(int i) {
if (i < 2) return 0;
if (i == 2 || i == 3) return 1;
if (i % 2 == 0 || i % 3 == 0) return 0;
for (int j = 5; j * j <= i; j += 6) {
if (i % j == 0 || i % (j + 2) == 0) {
return 0;
}
}
return 1;
}
int main() {
int N;
cin>>N;
for(int i=0;i<N;i++){
int n;
cin>>n;
if(isPr(n)){
cout <<"yes"<<endl;}
else{
cout <<"no"<<endl;}
}
return 0;
}

 问题2:     

         利用公式e=1+ 1/1! + 1/2! + 1/3! + … + 1/n!,编程计算e的近似值,直到最后一项的绝对值小于threshold(该项不包括在结果内),输出e的值并统计累加的项数。(计算e)

输入、输出要求:

        输入一个实数threshold,表示累加的阈值,数列中最后一项的值大于等于该阈值。Threshold最小可为1e-10。

        输出一个实数表示e的值,保留6位小数,并输出一个整数,表示累加的项数。两个数字之间用一个空格分隔,在行首和行尾没有多余的空格。

输入输出示例:

个人总结:

        1.本题的精度控制需要调用<iomanip> 。

实现代码如下示:

#include<iostream>
#include <iomanip>
using namespace std;
int main() {
double threshold,e=1.0,ct=1.0;
cin>>threshold;
int i=1;
if(threshold>1){e=0,i=0;cout <<fixed << setprecision(6) << e <<" "<<i;return 0;}
while(ct/i >= threshold){
ct=ct/i;
e=e+ct;
i++;
}
cout <<fixed << setprecision(6) << e <<" "<<i;
return 0;
}

 问题3:   

        输入一个正整数,求这个正整数的各位数字之和。(数字之和)

输入、输出要求:

        你的程序需要从标准输入设备(通常为键盘)中读入多组测试数据。每组测试数据为正整数,每行一个N,N小于20000。

        对每组测试数据,你的程序需要向标准输出文件(通常为启动该程序的文本终端)依次输出一组对应的答案:输出为它的各位数字之和,所有数据前后没有多余的空行,两组数据之间也没有多余的空行。

输入输出示例:

个人总结:

        1.本题简单,注意数字和变量初始化与输入数字中各位数字的处理。

实现代码如下示:

#include<iostream>
using namespace std;
int main(){
int N;
while((cin>>N)!= NULL){
int n=N,i=0;
int m[5]={0};
while(n>0){
m[i]=n%10;
n=n/10;
i++;
}i=0;
for(int j=0;j<6;j++){
i=i+m[j];
}
cout<<i<<endl;
}
return 0;
}

专业TOPIC翻译打卡:

第一段

英文原文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.

中文翻译要深入理解人工智能领域,了解该领域的研究沿着两条路径展开是很有帮助的。一条是工程路径,研究者致力于开发能表现出智能行为的系统。另一条是理论路径,研究者试图建立对动物(尤其是人类)智能的计算化理解。通过考察两条路径的研究方式,我们可以更清晰地理解这种二分法。工程路径导向以性能为核心的方法论,其根本目标是产出满足特定性能指标的产品。理论路径则导向以模拟为核心的方法论,其根本目标是拓展我们对智能的理解,因此更强调底层过程而非外在表现。

第二段

英文原文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.

中文翻译以自然语言处理和语言学为例。这两个领域联系紧密,并且能相互受益,但它们的根本目标不同。语言学家关注人类如何处理语言,因此更倾向于理论研究。而自然语言处理领域的研究者则致力于开发能够处理自然语言的机器,因此更偏向工程方向。因此,语言学家采用以模拟为导向的模式 —— 构建系统的目的是验证理论。相比之下,自然语言处理研究者采用以性能为导向的模式 —— 构建系统是为了执行任务。后者模式下开发的系统(如文档翻译器、响应语音指令的机器系统)虽然大量依赖语言学家的研究成果,但通常会采用一些 “捷径”,这些捷径仅在特定系统的受限环境中有效。

3. 第三段

英文原文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” 等其他命令区分开即可。因此,该外壳只需将输入与预设的音频模式进行匹配就能完成任务。这样的系统性能可能令工程师满意,但它的实现方式在理论学家看来可能缺乏美感。

专业名词与生词:

ngineering track / theoretical track 工程路径 / 理论路径

performance-oriented methodology 以性能为导向的方法论

simulation-oriented methodology 以模拟为导向的方法论

natural language processing (NLP) 自然语言处理

shell 外壳程序(操作系统术语)

verbal commands 语音指令

connotation 隐含意义;内涵

plagiarism 抄袭;剽窃

theoretician 理论学家

appreciate 深入理解;充分认识

dichotomy 二分法;对立

underlying 根本的;底层的

exterior 外在的;表面的

manipulate 处理;操控

restricted environment 受限环境

predetermined 预设的

aesthetically pleasing 在美学上令人满意的

赞(0)
未经允许不得转载:171主机测评 » 素数、计算e、数字之和——Day11
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址