【day37】
这些方面包括模仿机器人的物理特性,模仿它的环境计划,它的动作指引,高效操作它的机械装置,使用传感器向控制程序提供反馈,以及保证他行为安全性。我们做好了题目的解答,提交之后,要么“AC”,要么错误,不管怎样错法,总是给你记上一笔,表明你曾经有过一次错误提交,因而当你一旦提交该题“AC”后,就要与你算一算帐了,总共该题错误提交了几回。这样一来,你在做出的题数上,可能领先别人很多,但是,在做出同样题数的
题目:
给你两个正的实数A和B,你的任务是计算出A+B的值。
个人总结:
- 注意小数点后的计算
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string add109(string a, string b) {
string sum = "";
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int lena = a.size();
int lenb = b.size();
int i = 0, j = 0, ka, kb, add, extra = 0;
while (i < lena && j < lenb) {
ka = (int)(a[i] - '0');
kb = (int)(b[j] - '0');
add = ka + kb + extra;
extra = add / 10;
add = add % 10;
sum.push_back(add + '0');
i++;
j++;
}
while (i < lena) {
ka = (int)(a[i] - '0');
add = ka + extra;
extra = add / 10;
add = add % 10;
sum.push_back(add + '0');
i++;
}
while (j < lenb) {
kb = (int)(b[j] - '0');
add = kb + extra;
extra = add / 10;
add = add % 10;
sum.push_back(add + '0');
j++;
}
if (extra != 0) {
sum.push_back(extra + '0');
}
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
reverse(sum.begin(), sum.end());
return sum;
}
string freg1(string a) {
string b = "";
for (char c : a) {
if (c != '.')b += c;
else return b;
}
return b;
}
string freg2(string a) {
string b = "";
int flag = 0;
for (char c : a) {
if (flag)b += c;
if (c == '.')flag = 1;
}
return b;
}
int main() {
int n;
cin >> n;
while (n>0) {
n--;
string a, b, sum;
cin >> a >> b;
string ai = freg1(a), bi = freg1(b);
string af = freg2(a), bf = freg2(b);
int m = max(af.size(), bf.size());
while (af.size() < m) af.push_back('0');//小数部分右侧补零到同长度
while (bf.size() < m) bf.push_back('0');
string fs = (m == 0) ? "" : add109(af, bf);
string carry = "0";
if (m > 0) {
if (fs.size() > m) {
carry = "1";
fs = fs.substr(1);//去掉最高位
}
else {
while (fs.size() < m) fs = "0" + fs;
}
}
string is = add109(ai, bi);
if (carry == "1") is = add109(is, "1");
while (!fs.empty() && fs.back() == '0') fs.pop_back();//去掉小数末尾多余0
if (fs.empty()) cout << is << endl;
else cout << is << "." << fs << endl;
}
return 0;
}
题目:
C++编程考试使用的实时提交系统,具有即时获得成绩排名的特点。它的功能是怎么实现的呢?
我们做好了题目的解答,提交之后,要么“AC”,要么错误,不管怎样错法,总是给你记上一笔,表明你曾经有过一次错误提交,因而当你一旦提交该题“AC”后,就要与你算一算帐了,总共该题错误提交了几回。虽然你在题数上,大步地跃上了一个台阶,但是在耗时上要摊上你共花去的时间。特别是,曾经有过的错误提交,每次都要摊上一定的单位时间分。这样一来,你在做出的题数上,可能领先别人很多,但是,在做出同样题数的人群中,你可能会在耗时上处于排名的劣势。
例如:某次考试一共8题(A,B,C,D,E,F,G,H),每个人做的题都在对应的题号下有个数量标记,负数表示该学生在该题上有过的错误提交次数,但到现在还没有AC,正数表示AC所耗的时间,如果正数a跟上一对括号,里面有个整数b,那就表示该学生提交该题AC了,耗去了时间a,同时,曾经错误提交了b次(如果b为0则没有括号及b),因此对于下述输入数据:

若每次错误提交的罚分为20分,即每错误提交一次,在总耗时时增加20分钟,则其排名从高到低应该是这样的:
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0
个人总结:
- 利用结构体
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
struct Student {
string name;
int solved = 0;
int penalty = 0;
};
int main() {
int n, m;
cin >> n >> m;
vector<Student> stu;
string name;
while (cin >> name) {
Student s;
s.name = name;
for (int i = 0; i < n; ++i) {
string token;
cin >> token;
size_t p = token.find('(');//定位‘(’的位置
int t = 0;
int wrong = 0;
if (p == string::npos) {
t = stoi(token);//string转int
}
else {
t = stoi(token.substr(0, p));//用时
size_t q = token.find(')', p);
wrong = stoi(token.substr(p + 1, q - p - 1));//提取括号里的数字(错误提交次数)
}
if (t > 0) {
s.solved++;
s.penalty += t + wrong * m;
}
}
stu.push_back(s);
}
sort(stu.begin(), stu.end(), [](const Student& a, const Student& b) {
if (a.solved != b.solved) return a.solved > b.solved;
if (a.penalty != b.penalty) return a.penalty < b.penalty;
return a.name < b.name;
});
for (const auto& s : stu) {
cout << left << setw(10) << s.name << ' '
<< right << setw(2) << s.solved << ' '
<< right << setw(4) << s.penalty << '\n';
}
return 0;
}
题目:
设有3个候选人zhang、li、wang(候选人姓名不区分大小写),10个选民,选民每次输入一个得票的候选人的名字,若选民输错候选人姓名,则按废票处理。选民投票结束后,程序自动显示各候选人的得票结果和废票信息。要求用结构体数组candidate表示3个候选人的姓名和得票结果。
#include <iostream>
#include<vector>
using namespace std;
struct candidate
{
string name;
int score = 0;
};
int main() {
vector<candidate>p(3);
p[1].name = "zhang";
p[0].name = "li";
p[2].name = "wang";
string ticket;
int wrong = 0;
while (cin >> ticket) {
if (ticket.empty())break;
else if (ticket == "zhang")p[1].score++;
else if (ticket == "li")p[0].score++;
else if (ticket == "wang")p[2].score++;
else wrong++;
}
for (int i = 0; i < 3; i++) {
cout << p[i].name << ":" << p[i].score << endl;
}
cout << "Wrong election:" << wrong << endl;
return 0;
}
Translation:
Computer architecture is the design and analysis of new computer systems. Computer architects study ways of improvingcomputers by increasing their speed, storage capacity, andreliability, and by reducing their cost and power consumption.Computer architects develop both software and hardware models to analyze the performance of existing and proposedcomputer designs, and then use this analysis to guide thedevelopment of new computers. They are often involved withthe engineering of a new computer because the accuracy of their models depends on the design of the computer's circuitry.Many computer architects are interested in developingcomputers that are specialized for particular applications such asimage processing, signal processing, or the control ofmechanical systems. The optimization of computer architecture to specific tasks often yields higher performance, lower cost, or both.
计算机体系结构是对新型计算机系统的设计与分析。计算机架构师研究改进计算机的方法,包括提高其速度、存储容量和可靠性,以及降低其成本和功耗。计算机架构师会开发软件和硬件模型,以分析现有和拟议计算机设计的性能,然后利用这种分析来指导新型计算机的研发。他们通常会参与新型计算机的工程设计,因为其模型的准确性取决于计算机电路的设计。许多计算机架构师热衷于研发专门用于特定应用的计算机,例如图像处理、信号处理或机械系统控制等领域。针对特定任务对计算机体系结构进行优化,往往能带来更高的性能、更低的成本,或者两者都有。
- yield 产生、放弃
Artificial intelligence (AI) research seeks to enable computersand machines to mimic human intelligence and sensoryprocessing ability, and models human behavior with computersto improve our understanding of intelligence. The many branches of AI research include machine learning, inference,cognition, knowledge representation, problem solving,casebased reasoning, natural language understanding, speech recognition, computer vision, and artificial neural networks.
人工智能研究追寻着让计算机和机器能够模仿人类智能和处理感情感官处理能力的功能,以及用计算机模仿人类的行为来提升我们对智能的理解。人工智能研究其中许多的分支,包括计算机学习、推理、认知、知识表示、问题解决基于案例的推理、自然与语言理解、声音识别、计算机视觉和人工神经网络。
- mimic 模仿
- inference 推理
Another area of computer science that has found wide practical use is robotics—the design and development of computer controlled mechanical devices. Robots range in complexity from toys to automated factory assembly lines, and relieve humans from tedious, repetitive, or dangerous tasks. Robots are also employed where requirements of speed, precision, consistency,or cleanliness exceed what humans can accomplish.Roboticists—scientists involved in the field of robotics—study the manyaspects of controlling robots. These aspects include modelingthe robot's physical properties, modeling its environment,planning its actions, directing its mechanisms efficiently, usingsensors to provide feedback to the controlling program, andensuring the safety of its behavior. They also study ways ofsimplifying the creation of control programs. One area ofresearch seeks to provide robots with more of the dexterity andadaptability of humans, and is closely associated with AI.
计算机科学另一个被发现有广泛使用性的领域是机器人——也就是计算机控制的机械设备的设计和发展。机器人的复杂程度从玩具到自动化工厂装配线,让人类摆脱了冗长重复或危险的任务。机器人同样被应用于需要速度精准性持久性或超出人类能够解决的范围的地方。机器学家——也就是机器领域的科学家——研究控制机器人的许多方面。这些方面包括模仿机器人的物理特性,模仿它的环境计划,它的动作指引,高效操作它的机械装置,使用传感器向控制程序提供反馈,以及保证他行为安全性。简化控制程序创造。研究的一个领域试图向机器人提供更强的人类所拥有的敏捷性和适应性这一领域和AI紧紧相关联。
- dexterity 敏捷
- mechanism 机械装置

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐

所有评论(0)