基础76:给你一张5行5列的效益表,表中的数字均为大于等于0的整数,要求在这张表中选出5个数字,使这5个数字的和最大。
cpp
#include <stdio.h>
#include <string.h>
int main() {
int matrix[5][5];
int row = 5, col =5;
while (1) {
// 尝试读入一个5×5矩阵
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
if (scanf("%d", &matrix[i][j]) != 1) {
// 如果读不到足够的数字(如遇到EOF),则结束程序
return 0; // 直接退出
}
}
}
// printf("\n");
// printf("\n");
// // 输出验证
// for (int i = 0; i < row; i++) {
// for (int j = 0; j < col; j++) {
// printf("%d ", matrix[i][j]);
// }
//
// printf("\n");
// }
//算法
//遍历数组。每次找到最大值,将所在行和列其他位置设为0,
int CompareValue=-1;
int RowIndex,ColIndex;
int count = row;//找到5个最大值
int ans=0;
while(count--){
for(int i=0;i<row;i++){
for(int j=0;j<row;j++){
if(matrix[i][j] > CompareValue){
CompareValue=matrix[i][j];
RowIndex = i;
ColIndex = j;
}
}
}//找到最大值
for(int i=0;i<row;i++){
matrix[i][ColIndex]=0;
}
for(int i=0;i<row;i++){
matrix[RowIndex][i]=0;
}
ans +=CompareValue;
CompareValue = -1;
}
printf("%d\n", ans);
}
return 0;
}
-
接收多组固定相同大小的矩阵
while (1) { // 尝试读入一个5×5矩阵 for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (scanf("%d", &matrix[i][j]) != 1) { // 如果读不到足够的数字(如遇到EOF),则结束程序 return 0; // 直接退出 } } }
//成功读入后开始处理
int ans=0;
.......
基础77:给你一个正整数n,请你按题目描述中所述的方法,构造出n阶的螺旋方阵。
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
cpp
#include <stdio.h>
#include <stdlib.h>
int main(){
int n=0;
while(scanf("%d",&n) != EOF){
int ans[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
ans[i][j] = 0;
}
}
//算法
int count = 1;
int CurrentHang=0;
int CurrentLie=0;
//边界
int HangMax = n -1;
int LieMax = n -1;
int HangMin=0;
int LieMin=0;
while(count <= n*n){
//0.判断朝向,每一圈的顺序都是右、下、左、上
//判断朝右
if(CurrentHang==HangMin && CurrentLie<LieMax){
//朝右移动
for(int j= CurrentLie;j<=LieMax;j++){
if(ans[CurrentHang][j]!=0)j++;
ans[CurrentHang][j] = count;
count++;
CurrentLie=j;
}
}
if(count > n*n) break;
//判断超下
if(CurrentLie==LieMax&&CurrentHang==HangMin){
//朝下移动
for(int i=CurrentHang+1;i<=HangMax;i++){
ans[i][CurrentLie] = count;
count++;
CurrentHang=i;
}
// //修改界限
// HangMin++;
// LieMax--;
}
if(count > n*n) break;
//判断超左
if(CurrentHang==HangMax && CurrentLie==LieMax) {
//达到最大值,修改界限
HangMin++;
LieMax--;
for(int j=CurrentLie-1;j>=LieMin;j--){
ans[CurrentHang][j] = count;
count++;
CurrentLie=j;
}
}
if(count > n*n) break;
//判断超上
if(CurrentHang==HangMax && CurrentLie==LieMin){
//达到最大值,修改界限
HangMax--;
//4.上
for(int i=CurrentHang-1;i>=HangMin;i--){
ans[i][CurrentLie] = count;
count++;
CurrentHang=i;
}
LieMin++;
}
if(count > n*n) break;
// //验证
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// printf("%d ",ans[i][j]);
// }
// printf("\n");
//
// }
// printf("\n");
}//算法循环
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%d",ans[i][j]);
if(j!=n-1)printf(" ");
}
printf("\n");
}
}
}
基础78:一块N x N(1=<N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案。写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式:
#1:转90度:图案按顺时针转90度。#2:转180度:图案按顺时针转180度。#3:转270度:图案按顺时针转270度。#4:反射:图案在水平方向翻转(形成原图案的镜像)。#5:组合:图案在水平方向翻转,然后按照#1-#3之一转换。#6:不改变:原图案不改变。#7:无效转换:无法用以上方法得到新图案。
cpp
#include <stdio.h>
#include <stdlib.h>
int main(){
int scale=0;
scanf("%d",&scale);
getchar(); // 吃掉数字后面的回车
char Orgin[scale][scale];
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
scanf(" %c",&Orgin[i][j]);
}
}//接收输入
char NewM[scale][scale];
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
scanf(" %c",&NewM[i][j]);
}
}//接收输入
//算法部分
//1.辅助数组
char TestM[scale][scale];
//法1旋转90度:第一行变成第三列,第二行变成第二列
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
TestM[j][scale-1-i]=Orgin[i][j];
}
}
//校验
int check=1;
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
if(TestM[i][j]!=NewM[i][j]){
check=0;
break;
}
}
if(check==0)break;
}
if(check==1){
printf("1\n");
return 0;
}
//法2 转180:左右颠倒,行顺序颠倒
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
TestM[scale-1-i][scale-1-j]=Orgin[i][j];
}
}
//校验
check=1;
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
if(TestM[i][j]!=NewM[i][j]){
check=0;
break;
}
}
if(check==0)break;
}
if(check==1){
printf("2\n");
return 0;
}
//法3:逆90度,第一行变第一列
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
TestM[scale-1-j][i]=Orgin[i][j];
}
}
//校验
check=1;
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
if(TestM[i][j]!=NewM[i][j]){
check=0;
break;
}
}
if(check==0)break;
}
if(check==1){
printf("3\n");
return 0;
}
//法4:镜像
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
TestM[i][scale-1-j]=Orgin[i][j];
}
}
//校验
check=1;
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
if(TestM[i][j]!=NewM[i][j]){
check=0;
break;
}
}
if(check==0)break;
}
if(check==1){
printf("4\n");
return 0;
}
//法5-1
char TempOrgin[scale][scale];
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
TempOrgin[i][scale-1-j]=Orgin[i][j];
}
}
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
TestM[j][scale-1-i]=TempOrgin[i][j];
}
}
//校验
check=1;
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
if(TestM[i][j]!=NewM[i][j]){
check=0;
break;
}
}
if(check==0)break;
}
if(check==1){
printf("5\n");
return 0;
}
//法5-2
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
TestM[scale-1-i][scale-1-j]=TempOrgin[i][j];
}
}
//校验
check=1;
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
if(TestM[i][j]!=NewM[i][j]){
check=0;
break;
}
}
if(check==0)break;
}
if(check==1){
printf("5\n");
return 0;
}
//法5-3
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
TestM[scale-1-j][i]=TempOrgin[i][j];
}
}
//校验
check=1;
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
if(TestM[i][j]!=NewM[i][j]){
check=0;
break;
}
}
if(check==0)break;
}
if(check==1){
printf("5\n");
return 0;
}
//法6:不变
check=1;
for(int i=0;i<scale;i++){
for(int j=0;j<scale;j++){
if(Orgin[i][j]!=NewM[i][j]){
check=0;
break;
}
}
if(check==0)break;
}
if(check==1){
printf("6\n");
return 0;
}
//全部未命中,返回7
printf("7\n");
printf("\n");
printf("\n");
// for(int i=0;i<scale;i++){
// for(int j=0;j<scale;j++){
// printf("%c",TestM[i][j]);
// }
// printf("\n");
// }//测试
}
A critical IoT application is promotion of a smart power grid. Various power companies across the United States have or are in the process of upgrading their power management and distribution systems. Various sensors at individual homes (smart thermostats) can collect information that is sent via a network to main stations (perhaps even local "hubs") that can apply complex power management and send control signals back to the grid to save energy. The smart grid is made possible by applying sensing, measurement, and control devices to electricity production, transmission, distribution, and consumption.
- smart power grid 智慧电网,thermostats 恒温器
- 一个重要的物联网重要 应用是对智慧电网的推广。整个美国的各种电力公司已经完成 或正在升级他们的电力管理与分配系统。每个家庭中的多种传感器能收集经由网络发送到主站的信息,主站能应用复杂的电力管理并将 发送控制信号发 返回电网来节省能源。智慧电网的构建,主要基于将感知传感 、测量和控制装置应用在电力生产、传输、分配和消耗的各个环节。
The IoT has been suggested in construction of smart buildings in residential, commercial, industrial, and government settings. A smart building can be a shopping mall or a home, a hospital or a high-rise office tower. Smart buildings need monitoring and regulation of heating, air conditioning, lighting, and environmental changes. They can oversee building security, fire suppression, and elevator operations. Smart building technologies focus on bringing more detailed monitoring and sensing "awareness" to buildings.
- has been suggested in 已被提出,high-rise 高层的,office tower 办公大楼,oversee 监督,fire suppression 消防
- 物联网已被提出用于在住宅、商业、工业和政府各种类型的智慧型建筑的建造。一个智慧型建筑可以是一个商场、一个房子、一家医院或是一个高层的办公大楼。智慧型建筑需要对供暖 、空调、照明和环境各个方面的变化的进行 监测和管理。他们能监督建筑的安全如消防和电梯运转。智慧型建筑技术聚焦于给建筑带来更详细的监管和感知意识。
A computer is an electronic device that can receive a set of instructions, or program, and then carry out this program by performing calculations on numerical data or by manipulating other forms of information.
- carry out 执行
- 电脑是一个电子器件装置,能够接收一系列指令或即程序,并基于计算数字数据或操作其他形式的信息来执行程序。