问题1:

        一家水果店出售四种水果,每公斤价格的苹果(代码为a)1.5元,橘子(代码为o)1.4元,香蕉(代码为b)1.48元,菠萝(代码为p)1.08元。编一个程序,使售货员只要在键盘上打入货品的代码及重量,计算机将显示货品名、单价、重量及总价。

输入、输出要求:

        你的程序需要从标准输入设备(通常为键盘)中读入多组测试数据。每组测试数据的第一行为一个整数m,表示有m件货品要被购买。在接下来的m行中,每行输入两个值d,g。d表示货品的代码,g表示重量。两组数据之间没有多余的空行。

        对每组测试数据,你的程序需要向标准输出设备(通常为启动该程序的终端)依次输出一组对应的答案。对应每组输入,输出货品名、单个总价及全部总价。具体格式参照样例输出:第一行apple前为7个空格,之后为2个空格,其他水果名后都是1个空格,sum后没有空格;第二行price后有2个空格,其后关于价格的表示多为占7格2位小数且左对齐,但其中pineapple为占10格2位小数且左对齐,注意sum的价格仍然占7格,如第一组样例中的54.60后还有2个空格;第三行weight后有1个空格,其后的数据与第二行一致。每两组数据之间有一个空行,最后一组测试数据之后没有空行。

输入输出示例:

个人总结:

        1.本题相对简单,主要在输出格式调整上比较麻烦。

实现代码如下示

#include <iostream>
using namespace std;
int main()
{
	int m;
	char d;
	double g;
	while(scanf("%d",&m)!=EOF)
	{
		double sum1=0,sum2=0;
		double weight[4]={0};
		double price[4]={0};
		for(int i=0;i<m;i++)
		{  
			getchar();
			d=getchar();
			scanf("%lf",&g);
			switch(d)
			{
			case 'a':
				price[0]+=1.5*g;
				weight[0]+=g;
				break;
			case 'o':
				price[1]+=1.4*g;
				weight[1]+=g;
				break;
			case 'b':
				price[2]+=1.48*g;
				weight[2]+=g;
				break;
			case 'p':
				price[3]+=1.08*g;
				weight[3]+=g;
				break;
			}
		}
		for(int j=0;j<4;j++)
		{
			sum1+=price[j];
			sum2+=weight[j];
		}
		printf("       apple  orange banana pineapple sum\n");
		printf("price  %-7.2f%-7.2f%-7.2f%-10.2f%-7.2f\n",
            price[0],price[1],price[2],price[3],sum1);
		printf("weight %-7.2f%-7.2f%-7.2f%-10.2f%-7.2f\n",
            weight[0],weight[1],weight[2],weight[3],sum2);
		printf("\n");
	}
	return 0;
}

 问题2:     

        给你n个整数,求他们中所有奇数的乘积。

输入、输出要求:

        输入数据包含两行,第一行为一个数为n,表示第二行将输入n个整数。你可以假设这n个数据中必定至少存在一个奇数。

        输出一个整数。

输入输出示例:

个人总结:

        1.本题相对简单,接受N个数并逐个判断其是否为奇数,将序列中奇数累加即可;

实现代码如下示

#include<iostream>
using namespace std;
int main() {
    int N;
    cin>>N;
    int count=1;
    for(int i=1;i<=N;i++){
        int m;
        cin>>m;
        if(m%2==1){count=count*m;}
    }
    cout<<count;
    return 0;
}

问题3:   

        输入N个日期,每个以年、月、日的顺序读入,打印输出最晚的日期、最早的日期。

输入、输出要求:

        你的程序需要从标准输入设备(通常为键盘)中读入多组测试数据。每组输入数据由多行组成。每组测试数据的第一行输入一个整数N(0<N<20),表示有N个日期。其后N行每行有三个整数Y(1≤Y≤2015),M(1≤M≤12),D(1≤D≤31)表示一个日期。

        对每组测试数据,你的程序需要向标准输出设备(通常为启动该程序的文本终端)输出两行,每行包括3个整数,第一行为最晚日期,第二行为最早日期,整数之间以一个空格分隔,行首与行尾无空格,所有数据前后没有多余的空行,两组数据之间也没有多余的空行。

输入输出示例:

个人总结:

        1.本题有一定难度,按照逻辑对每一个输入日期分别与最晚日期,最早日期对比,其中判断部分注意由年到月再到日,如当前位相等则进一步对比下一位直到日为止。

实现代码如下示

#include<iostream>
using namespace std;
int main() {
    int N;
    cin>>N;
    int time[20][3]={0};
    int ltime=0,etime=0;
    for(int i=0;i<N;i++){
            int y,m,d;
            cin>>y>>m>>d;
            time[i][0]=y;
            time[i][1]=m;
            time[i][2]=d;
            if(time[ltime][0]<time[i][0]){
                ltime=i;}
            else if(time[ltime][0]==time[i][0]){
                    if(time[ltime][1]<time[i][1]){
                        ltime=i;}
                     else if(time[ltime][2]==time[i][2]){
                            if(time[ltime][2]<time[i][2]){
                                    ltime=i;
                            }
                        }
                    }
            
            if(time[etime][0]>time[i][0]){
                etime=i;}
            else if(time[etime][0]==time[i][0]){
                    if(time[etime][1]>time[i][1]){
                        etime=i;}
                    else if(time[etime][1]==time[i][1]){
                             if(time[etime][2]>time[i][2]){
                                 etime=i;}
                            }
                        }
        }
    cout << time[ltime][0] << " " << time[ltime][1] << " " << time[ltime][2] << endl;
    cout << time[etime][0] << " " << time[etime][1] << " " << time[etime][2] << endl;
    return 0;
}

专业TOPIC翻译打卡

译文

P1        在某些情况下,智能主体的响应能力会随着学习而不断提升。这种学习可以表现为形成过程性知识(学习 “如何做”),或是存储陈述性知识(学习 “是什么”)。过程性知识的学习通常涉及试错过程:主体会因错误动作受到 “惩罚”,因正确动作得到 “奖励”,从而学会恰当的行为。通过这种方法,研究者已经开发出能随着时间推移,在西洋跳棋、国际象棋等对抗性游戏中提升自身能力的智能主体。陈述性知识的学习则通常表现为扩展或修改主体知识库中的 “事实”。例如,棒球运动员必须不断调整自己的知识储备库,以便对未来事件做出理性的反应。

P2        要对刺激做出理性响应,智能主体必须 “理解” 其传感器接收到的刺激。也就是说,主体必须能够从传感器生成的数据中提取信息,或者说,主体必须具备感知能力。在某些情况下,这是一个直接的过程:例如,从陀螺仪获取的信号可以很容易地编码为适合计算的形式,从而用于确定响应。但在其他情况下,从输入数据中提取信息则非常困难,比如理解语音和图像。同样,主体必须能够以与其执行器兼容的方式生成响应。这可能是一个简单的过程,也可能要求主体生成完整的语句作为响应 —— 这意味着主体必须具备语音生成能力。因此,图像处理与分析、自然语言理解、语音生成等都是重要的研究领域。

P3        我们在此梳理出的这些主体特性,代表了人工智能领域过去和当下的研究方向。当然,这些特性并非完全独立。我们的目标是开发具备所有这些特性的主体,使其能够理解从环境中接收的数据,并通过学习过程形成新的响应模式,最终目标是最大化主体的能力。不过,通过分离不同类型的理性行为并独立研究它们,研究者可以获得一个立足点,之后再与其他领域的进展相结合,从而开发出更智能的主体。

原文

        In some cases an agent's responses improve over time as the agent learns. This could take the form of developing procedural knowledge (learning "how") or storing declarative knowledge (learning "what"). Learning procedural knowledge usually involves a trial-and-error process by which an agent learns appropriate actions by being punished for poor actions and rewarded for good ones.Following this approach, agents have been developed that, over time, improve their abilities in competitive games such as checkers and chess. Learning declarative knowledge usually takes the form of expanding or altering the "facts" in an agent's store of knowledge. For example, a baseball player must repeatedly adjust his or her database of knowledge from which rational responses to future events are determined.

        To produce rational responses to stimuli, an agent must "understand" the stimuli received by its sensors. That is, an agent must be able to extract information from the data produced by its sensors, or in other words, an agent must be able to perceive. In some cases this is a straightforward process. Signals obtained from a gyroscope are easily encoded in forms compatible with calculations for determining responses. But in other cases extracting information from input data is difficult. Examples include understanding speech and images. Likewise, agents must be able to formulate their responses in terms compatible with their actuators. This might be a straightforward process or it might require an agent to formulate responses as complete spoken sentences—meaning that the agent must generate speech. In turn, such topics as image processing and analysis, natural language understanding, and speech generation are important areas of research.

        The agent attributes that we have identified here represent past as well as current areas of research. Of course, they are not totally independent of each other. We would like to develop agents that possess all of them, producing agents that understand the data received from their environments and develop new response patterns through a learning process whose goal is to maximize the agent's abilities. However, by isolating various types of rational behavior and pursuing them independently, researchers gain a toehold that can later be combined with progress in other areas to produce more intelligent agents.

专业名词

intelligent agents 智能主体(智能代理)

procedural knowledge 过程性知识(“如何做” 的知识)

declarative knowledge 陈述性知识(“是什么” 的知识)

trial-and-error process 试错过程

checkers 西洋跳棋(AI 博弈领域常见示例)

store of knowledge / database of knowledge 知识库

stimuli 刺激(传感器输入的触发信号)

sensors 传感器

gyroscope 陀螺仪(机器人 / 导航领域传感器)

actuators 执行器

image processing and analysis 图像处理与分析

natural language understanding (NLU) 自然语言理解

speech generation 语音生成

agent attributes 主体特性

rational behavior 理性行为

intelligent agents 智能主体(智能代理)

procedural knowledge 过程性知识(“如何做” 的知识)

declarative knowledge 陈述性知识(“是什么” 的知识)

trial-and-error process 试错过程

checkers 西洋跳棋(AI 博弈领域常见示例)

store of knowledge / database of knowledge 知识库

stimuli 刺激(传感器输入的触发信号)

gyroscope 陀螺仪(机器人 / 导航领域传感器)

actuators 执行器

image processing and analysis 图像处理与分析

natural language understanding (NLU) 自然语言理解

speech generation 语音生成

agent attributes 智能体特性

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐