一、上机打卡
1.1 三角形的个数
1.1.1 题目
明明的问题可以归结为:根据一个正整数n(3 ≤ n ≤ 100),要求统计出同时满足下列条件的三角形的个数:
-
边长都是整数。
-
周长为n。
-
边长两两不相等。
请你写一个程序来帮助明明计算出他认为他爸爸喜欢的三角形的个数。
输入说明
组测试数据,每组测试数据仅占一行,每行仅包括一个正整数n(3 ≤ n ≤ 100),代表需要被统计的三角形的周长,n的前后都没有任何空格。
输出说明
每组运算结果为一个大于等于0的整数构成,即满足条件的三角形的个数。输出时,每组运算结果占一行,其行首和行尾都没有任何空格或其他字符,每组运算结果与其后一组运算结果之间没有任何空行或其他字符,第一组运算结果前面以及最后一组运算结果后面也都没有任何空行或其他字符。
输入样例
15
30
输出样例
3
12
1.1.2 总结
两层for循环实现枚举所有可能的a,b,c。要使abc互不相等,且不枚举到同一组三角形,只要满足a<b<c即可。
要想让for循环枚举满足a<b<c的组合,之前一直在考虑abc的上界,但其实不用考虑,在for循环中使用if条件过滤掉不符合条件的组合即可。
1.1.3 代码
cpp
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
/*
保证a<b<c即可实现不统计重复的三角形,
之前一直在考虑abc的上界,以满足a<b<c,其
实不用考虑,代码里面使用if过滤掉即可
*/
int ans = 0;
for (int a = 1; a <= n; a ++) {
for (int b = a + 1; b <= n; b ++) {
int c = n - a - b;
if (a < b && b < c) {
if (a + b > c)
ans ++;
}
}
}
cout << ans << endl;
}
}
1.2 素数
1.2.1 题目
给你一个整数区间,求出在这个区间里共有多少个素数。
输入说明
每组测试数据仅有一行,每组测试数据有两个正整数M,N(0 < M ≤ N ≤ 1000000),表示一个整数区间。
输出说明
每组运算结果为一个整数,即区间[M, N]内一共有多少个素数。
输入样例
1 10
10 30
输出样例
4
6
1.2.2 总结
枚举M到N的每一个数,判断是否为素数即可。判断素数的方法前面的笔记多次描述过,这里不再赘述。
1.2.3 代码
cpp
#include <iostream>
using namespace std;
bool isPrime(int x) {
if(x == 1 || x == 0) return false;
for(int i = 2; i * i <= x; i++) {
if(x % i == 0) return false;
}
return true;
}
int main() {
int M, N;
while(cin >> M >> N) {
int ans = 0;
for(int i = M; i <= N; i++) {
if(isPrime(i)) ans++;
}
cout << ans << endl;
}
return 0;
}
1.3 杨辉三角
1.3.1 题目
还记得中学时候学过的杨辉三角吗?
基本的特征是:
前提:端点的数为1.
-
每个数等于它上方两数之和。
-
每行数字左右对称,由1开始逐渐变大。
-
第n行的数字有n项。
你可以参考以下的图形:

输入说明
输入数据首先包含一个正整数T ( T < 10 ),表示有 T 组测试数据, 每组测试数据只包含一个正整数n(1 <= n <= 20),表示将要输出的杨辉三角的层数。
输出说明
对应于每一个输入,请输出相应层数的杨辉三角,输出的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
输入样例
2
5
8
输出样例
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1.3.2 总结
使用二维数组实现杨辉三角,对于输入的N,创建一个N+1维(数组的行下标和列下标从1开始存储)的杨辉三角,初始化为0。第一列的元素初始化为1,对角线的元素初始化为1。从第三行开始,a[i][j] = a[i - 1][j] + a[i - 1][j - 1]。
1.3.3 代码
cpp
#include <iostream>
#include <vector>
using namespace std;
int main() {
int T;
cin >> T;
bool first = true;
while(T > 0) {
int n;
cin >> n;
//int a[n + 1][n + 1] = {0}; //增加一行一列,使行下标和列下标都从1开始
vector<vector<int>> a(n + 1, vector<int>(n + 1, 0));
for(int i = 1; i <= n; i ++) { //第一列和对角线1都为1
a[i][1] = 1;
a[i][i] = 1;
}
for(int i = 3; i <= n; i ++) { //从第三行到第n行
for(int j = 2; j < n; j ++) { //从第二列到第n-1列
a[i][j] = a[i - 1][j] + a[i - 1][j - 1];
}
}
if(!first) //每组空行分隔,一开始忽略了
cout << endl;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <=i; j ++) {
if(j != 1) cout << " "; //一开始写成了对i的判断
cout << a[i][j];
}
cout << endl;
}
first = false;
T--;
}
return 0;
}
二、翻译打卡
P1
原文:
Synergistic technologies play supporting roles. For example, biometrics could be widely applied to personalize the interactions among humans, machines, and objects. Artificial intelligence, computer vision, robotics, and telepresence can make our lives more automated in the future.
译文:
协同技术发挥重要作用。例如,生物识别技术可以被广泛应用于个性化性化人类、机器和物体之间的交互。人工智能,计算机视觉,机器人技术和远程呈现技术可以让我们的生活在未来变得更加自动化。
P2
原文:
As an emerging technology, the IoT will become more mature and more sophisticated. Figure 12C-1 shows the major technology advances and key applications that may benefit from the IoT. For example, supply chains are now better supported than before. Vertical market applications may represent the next wave of advances.Ubiquitous positioning is expected to become a reality as we move toward 2020. Beyond that, a physical IoT may be in place in a global scale. These advances will significantly upgrade human abilities,societal outcomes, national productivity, and quality of life.
译文:
作为一项新兴技术,物联网将变得更成熟和复杂。图12C-1展示了主要的能够从物联网获益的技术进步和关键的应用。例如供给链现在比之前获得了更多的供给。垂直市场应用可能代表了下一个进步的浪潮。随着我们走向2020年,无处不在的定位将有望实现。除此之外,一个物理上的物联网将出现在全球范围内。这些进步将显著地提升人类的能力,社会的结果,国家的生产力,以及生活的质量。
P3
原文:
The IoT system is likely to have an event-driven architecture. In Figure 12C-2, IoT development is shown with a three-layer architecture. The top layer is formed by driven applications. The application space of the IoT is huge. The bottom layers represent various types of sensing devices: namely RFID tags, ZigBee or other types of sensors, and road-mapping GPS navigators. The sensing devices are locally or wide-area-connected in the form of RFID networks,sensor networks, and GPSs. Signals orinformation collected at these sensingdevices are linked to the applicationsthrough the cloud computing platforms atthe middle layer.
译文:
物联网很可能有一个事件驱动架构。在图12C-2,物联网发展→开发被展示为三层架构。 最上层由驱动的应用程序组成。物联网的应用空间是巨大的。最底层代表各种类型的传感器:即 RFID 标签、ZigBee 或其他类型的传感器,以及道路测绘 GPS导航仪。传感器以 RFID 网络、传感器网络和GPS 的形式本地或广域连接。在这些传感器上收集的信号或信息通过中间层云计算平台与应用程序相连。
三、单词打卡
