【day27】

题目:

明明在上学的时候,参加数学兴趣班。在班上,老师介绍了一种非常有趣的阵列。

该阵列由n个正整数构成,阵列中的数字从1开始递增,数字的排序规则是从1开始由中间逆时针向外转出,2出现在1的下面,然后直至输出n为止。

例如当n=5的时候,阵列如下:

5

1 4

2 3

当n=9时,阵列如下:

7 6 5

8 1 4

9 2 3

当n=10时,阵列如下:

7 6 5

8 1 4

9 2 3

10

明明回家后想自己动手构造这样的阵列。他从n=1开始构造,但是他发现当n越来越大时,阵列的复杂性就越高,然后构造出来的阵列就越容易出错。为了降低构造阵列的出错率,提高构造速度,明明就求助于你,请你帮他写一个程序,来构造这样的阵列。

明明的问题可以归结为:给你一个正整数n,请你按题目描述中所述的方法,构造出阵列。

个人总结:

  1. 运用了之前题目的螺旋矩阵的方法但尝试过后还是没做出
cpp 复制代码
//错误代码:格式
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n;
    while (cin >> n) {
        int a[30][30] = { 0 };
        int num = 1;
        int center = 15; 
        a[center][center] = num++; 
        int l = center, r = center, t = center, d = center;
        int step = 1; 
        while (num <= n) {
            d++;
            if (num <= n) a[d][r] = num++;
            for (int i = 0; i < step && num <= n; i++) {
                r++;
                a[d][r] = num++;
            }
            for (int i = 0; i < step && num <= n; i++) {
                t--;
                a[t][r] = num++;
            }
            step++; 
            for (int i = 0; i < step && num <= n; i++) {
                l--;
                a[t][l] = num++;
            }
            for (int i = 0; i < step && num <= n; i++) {
                d++;
                a[d][l] = num++;
            }
            step++; 
        }
        int min_r = 30, max_r = -1;
        int min_c = 30, max_c = -1;
        for (int i = 0; i < 30; i++) {
            for (int j = 0; j < 30; j++) {
                if (a[i][j] != 0) {
                    min_r = min(min_r, i);
                    max_r = max(max_r, i);
                    min_c = min(min_c, j);
                    max_c = max(max_c, j);
                }
            }
        }
        for (int i = min_r; i <= max_r; i++) {
            for (int j = min_c; j <= max_c; j++) {
                if (a[i][j] != 0) {
                    cout <<  a[i][j];
                }
                else {
                    cout << "  ";
                }
                if (j != max_c) {
                    cout << " "; 
                }
            }
            cout << endl;
        }
    }
    return 0;
}

题目:

农夫约翰从来只用调配得最好的饲料来为他的奶牛。

饲料用三种原料调配成:大麦,燕麦和小麦。他知道自己的饲料精确的配比,在市场上是买不到这样的饲料的。他只好购买其他三种混合饲料(同样都由三种麦子组成),然后将它们混合,来调配他的完美饲料。

给出三组整数,表示 大麦:燕麦:小麦 的比例,找出用这三种饲料调配 x:y:z 的饲料的方法。

例如,给出目标饲料 3:4:5 和三种饲料的比例:

1:2:3

3:7:1

2:1:2

你必须编程找出使这三种饲料用量最少的方案,要是不能用这三种饲料调配目标饲料,输出'NONE'。'用量最少'意味着三种饲料的用量(整数)的和必须最小。

对于上面的例子,你可以用8份饲料1,2份饲料2,和5份饲料3,来得到7份目标饲料: 8*(1:2:3) + 1*(3:7:1) + 5*(2:1:2) = (21:28:35) = 7*(3:4:5)

以上数字中,表示饲料比例的整数都是小于100(数量级)的非负整数,表示各种饲料的份数的整数都小于100。一种混合物的比例不会由其他混合物的比例直接相加得到。

个人总结:

  1. 利用克莱默法则
cpp 复制代码
#include<iostream>
using namespace std;
int main() {
	int final[3];
	int a[3], b[3], c[3];
	for (int i = 0; i < 3; i++) {
		cin >> final[i];
	}
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 3; i++) {
		cin >> b[i];
	}	
	for (int i = 0; i < 3; i++) {
		cin >> c[i];
	}
	for (int n = 1; n <= 100; n++) {
		int target[3] = {final[0] * n,final[1] * n,final[2] * n};
		int d = a[0] * b[1] * c[2] + a[1] * b[2] * c[0] + a[2] * b[0] * c[1] - a[2] * b[1] * c[0] - a[0] * b[2] * c[1] - a[1] * b[0] * c[2];
		if (d == 0)continue;
		int d1=target[0] * b[1] * c[2]+ target[1] * b[2] * c[0] + target[2] * b[0] * c[1] - target[2] * b[1] * c[0] - target[0] * b[2] * c[1] - target[1] * b[0] * c[2];
		int d2= a[0] * target[1] * c[2] + a[1] * target[2] * c[0] + a[2] * target[0] * c[1] - a[2] * target[1] * c[0] - a[0] * target[2] * c[1] - a[1] * target[0] * c[2];
		int d3= a[0] * b[1] * target[2] + a[1] * b[2] * target[0] + a[2] * b[0] * target[1] - a[2] * b[1] * target[0] - a[0] * b[2] * target[1] - a[1] * b[0] * target[2];
		if (d1 % d != 0 || d2 % d != 0 || d3 % d != 0) continue;//配比为整数,消除配比不为整数的情况
		int x1 = d1 / d, x2 = d2 / d, x3 = d3 / d;
		if (x1 < 0 || x2 < 0 || x3 < 0)continue;//大于0!!
		cout << x1 << " " << x2 << " " << x3 << " " << n << endl;
		return 0;
	}
	cout << "NONE" << endl;
	return 0;
}

题目:

明明最近在一家软件公司实习,公司分配给他一个任务,要他写一个小程序,这个程序的功能是求出一个浮点数的小数部分的长度。例如程序输入1.1,则输出1,程序输入1.11,则输出2,明明觉得这个非常简单,花了不到5分钟的时间就把程序给写出来了,然后就把程序交给了测试员测试。但是没有想到的是,经过测试员的测试,发现了一大堆的错误,返回的结果很多都是不对的,这个令明明相当的不解,始终想不通自己的程序错在哪里。你是一名经验丰富的程序员,明明把这个问题来求助于你,明明和你说了他的想法,你一听就明白明明错在了哪里,原来明明使用double型来存放浮点数,但是由于double型的精度问题,不可能把所有的小数都精确的保存好,如果小数位数很长,就会出错。你发现了问题。现在请你写出正确的程序。 明明的问题可以归结为:给你一个浮点数,请你求出这个浮点数的小数位数。

cpp 复制代码
#include<string>
#include<iostream>
using namespace std;
int cnt;
int main() {
	string a;
	while (cin >> a) {
		int len = a.size();
		int cnt = 0;
		int flag = 0;
		for (int i = 0; i < len; i++) {
			if (flag)cnt++;
			if (a[i] == '.') {
				flag = 1;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Translation:

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 ora high-rise office tower. Smart buildings need monitoring and regulation of heating, air conditioning, lighting, andenvironmental changes. They can oversee building security, fire suppression, and elevator operations. Smart buildingtechnologies focus on bringing more detailed monitoring andsensing "awareness" to buildings.

物联网被建议投入到在居民、商业、工业和政府设施中建设智能大楼。一栋智能大楼可以是一座商场或一处住宅,一所医院或者一幢高耸入云的办公楼。智能大楼需要监控和管理加热、空调、灯光和环境变化。它们监管大楼的安全性、火情抑制和电梯运行。智能大楼科技聚焦于带来更细节的监控和大楼的传感感知能力。

  • oversee 监管

A computer is an electronic device that can receive a set ofinstructions, or program, and then carry out this program by performing calculations on numerical data or by manipulatingother forms of information.

电脑是一台可以接受一系列指令或程序的电子设备,它通过计算数值数据或操作其他类型的信息来执行程序。

  • numerical 数值的

The modern world of high technology could not have come about except for the development of the computer. Differenttypes and sizes of computers find uses throughout society in thestorage and handling of data, from secret governmental files tobanking transactions to private household accounts. Computershave opened up a new era in manufacturing through thetechniques of automation, and they have enhanced moderncommunication systems. They are essential tools in almost everyfield of research and applied technology, from constructingmodels of the universe to producing tomorrow's weatherreports, and their use has in itself opened up new areas ofconjecture. Database services and computer networks makeavailable a great variety of information sources. The same advanced techniques also make possible invasions of personal and business privacy. Computer crime has become one of themany risks that are part of the price of modern technology.

没有电脑的发展就不能实现高科技的现代世界。不同种类尺寸的计算机在全社会里发挥其作用,用于储存处理数据,从机密政府文件到银行交易私人家庭账号。计算机通过自动化技术开启了制作业新的时代,它们增强了现代交流系统。它们在研究和应用技术的几乎每个领域都是必要的工具,从建造宇宙模型到生产明天的天气报告,它们在自身上的运用开启预测的新时代。数据库服务和计算机网络提供了大量不同的信息来源。相同的进步技术同样让侵犯私人和企业隐私成为可能。计算机犯罪已成为众多风险的一部分,这一风险是现代技术所带来的部分代价。

  • conjecture 预测 推测

相关推荐
望舒5132 小时前
代码随想录day32,动态规划part1
java·算法·leetcode·动态规划
楠秋9202 小时前
代码随想录算法训练营第三十二天| 509. 斐波那契数 、 70. 爬楼梯 、746. 使用最小花费爬楼梯
数据结构·算法·leetcode·动态规划
㓗冽2 小时前
最大效益(二维数组)-基础题76th + 螺旋方阵(二维数组)-基础题77th + 方块转换(二维数组)-基础题78th
数据结构·算法
Ivanqhz2 小时前
数据流分析的核心格(Lattice)系统
开发语言·javascript·后端·python·算法·蓝桥杯·rust
琛説2 小时前
⚡PitchPPT:将PPT导出为高清全图PPT,并控制PPT文件大小在固定MB/GB以内【解析算法原理 · 作者谈】
windows·python·算法·github·powerpoint
We་ct2 小时前
LeetCode 25. K个一组翻转链表:两种解法详解+避坑指南
前端·算法·leetcode·链表·typescript
Hag_202 小时前
LeetCode Hot100 438.找到字符串中的所有字母异位词
算法·leetcode·职场和发展
元亓亓亓2 小时前
LeetCode热题100--239. 滑动窗口最大值--困难
数据结构·算法·leetcode
闻缺陷则喜何志丹2 小时前
【进制】P2320 [HNOI2006] 鬼谷子的钱袋|普及+
c++·算法·进制