东华复试OJ每日3题打卡·复盘79~81

基础79:给你一个正整数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

cpp 复制代码
#include <stdio.h>
#include <stdlib.h>

int main(){
    int n;
    scanf("%d", &n);

    int scale;
    for(int i=1;i<=n/2;i++){
        if(i*i == n-1 ||i*i == n || i*i>n){
            scale=i;//确定矩阵规模
            break;
        }
    }
   // printf("scale=%d\n",scale);
    
    int width;
    if(n/10==0)width=2;
    else width=1;
    
    
    //辅助数组
    int matrix[scale][scale];
    for(int i=0;i<scale;i++){
        for(int j=0;j<scale;j++){
            matrix[i][j]=0;
        }
    }
    //初始值
    int num=1;
    int RowIndex,ColIndex;
    if(scale%2==0){
        RowIndex = scale/2-1;
        ColIndex = scale/2-1;
    }
    else{
        RowIndex = scale/2;
        ColIndex = scale/2;
    }

    int CurrentScale=0;//当前构建规模
    int newScale=0;//表示进入新的矩阵规模

    //两种移动方式,下1 n右上和上1 n左下,根据current+1的奇偶性
    int DRU = 0;//下右上为1,每次变动规模使其等于+1%2
    while(num<n){
        //决定移动方向
        
        //新进来的位置
        matrix[RowIndex][ColIndex] = num;
        num++;

        if(DRU){//n右上的移动语句
            for(int i=0;i<CurrentScale;i++){
                ColIndex++;
                matrix[RowIndex][ColIndex] = num;
                num++;
            }//右移动
            for(int i=0;i<CurrentScale;i++){
                RowIndex--;
                matrix[RowIndex][ColIndex] = num;
                num++;
            }//上移动
            }
        else{//n左下的移动语句
            for(int i=0;i<CurrentScale;i++){
                ColIndex--;
                matrix[RowIndex][ColIndex] = num;
                num++;
            }//左移动
            for(int i=0;i<CurrentScale;i++){
                RowIndex++;
                matrix[RowIndex][ColIndex] = num;
            	num++;
            }//下移动
        }

        //进新位置下1 或 上1
        CurrentScale++;
        DRU = (DRU+1)%2;
        if(DRU == 1){
            RowIndex++;
        }//奇数规模向下走
        else{
          RowIndex--;
        } //上移动 
          
		  
		  
//		  //测试  
//         for(int i=0;i<scale;i++){
//	        for(int j=0;j<scale;j++){
//	            printf("%d ",matrix[i][j]); 
//	        }
//        	printf("\n");
//    	}   
//          printf("\n");
//		  printf("\n");  
//		  
    }
    //确定要不要额外输出一行为 n 
    //偶数输出在第一行 
	if(scale*scale == n-1){
		if( (n-1) % 2 ==0){
			for(int i=0;i<scale-1;i++){
				printf("%*s",width,"");
			}
			printf("%*d\n",width,n);
		}
	} 
	
	 
    for(int i=0;i<scale;i++){
        for(int j=0;j<scale;j++){
        	if(matrix[i][j] <= n){
        		printf("%*d",width,matrix[i][j]);	 
			}
			else printf("%*s",width,"");   
        }
        printf("\n");
    }
    //奇数输出在最后一行
	if(scale*scale == n-1){
		if( (n-1) % 2 ==1){	
			printf("%*d",width,n); 
		}
	}  
        
        
}

基础80:

例如,给出目标饲料 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)

cpp 复制代码
#include <stdio.h>
#include <stdlib.h>

int main(){
    int matrix[4][3];
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            scanf("%d", &matrix[i][j]);
        }
    }//接收输入

//    for(int i=0;i<4;i++){
//        for(int j=0;j<3;j++){
//            printf("%d ", matrix[i][j]);
//        }
//        printf("\n");
//    }//验证

    //1.矩阵运算,后三行线性组合表示第一行
    //暴力法,从1~10遍历共10*10*10次

    int num[3];
    for(int x=0;x<100;x++){
        for(int y=0;y<100;y++){
            for(int z=0;z<100;z++){
               num[0] = x*matrix[1][0] + y*matrix[2][0] + z*matrix[3][0];
                num[1] = x*matrix[1][1] + y*matrix[2][1] + z*matrix[3][1];
                num[2] = x*matrix[1][2] + y*matrix[2][2] + z*matrix[3][2];
                int Xishu = num[0]/matrix[0][0];
                if(Xishu==0) continue;
                if(Xishu*matrix[0][0]==num[0] && Xishu*matrix[0][1]==num[1]&&
                    Xishu*matrix[0][2]==num[2]){
                    printf("%d %d %d %d\n",x,y,z,Xishu);
                    
                    return 0;
                    }
            }
        }
    }
    printf("NONE");
    
    
}

基础81:给你一个浮点数,请你求出这个浮点数的小数位数。

cpp 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    char num[100];

    while( scanf("%s",num) != EOF){
        char * dot = strchr(num, '.');
        if(dot == NULL){
            printf("0\n");
            continue;
        }
        int spacing = strlen(dot + 1);
        printf("%d\n",spacing);
    }
    
    return 0;
    
}

strchr(主串变量, '单个字符'),返回指向该字符的指针,即地址,没有找到则为NULL

strlen(字符起始地址),返回该起始地址知道字符串结束标识符的长度


The modern world of high technology could not have come about except for the development of the computer. Different types and sizes of computers find uses throughout society in the storage and handling of data, from secret governmental files to banking transactions to private household accounts. Computers have opened up a new era in manufacturing through the techniques of automation, and they have enhanced modern communication systems. They are essential tools in almost every field of research and applied technology, from constructing models of the universe to producing tomorrow's weather reports, and their use has in itself opened up new areas of conjecture. Database services and computer networks make available 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 the many risks that are part of the price of modern technology.

  • come about 发生/产生,household 家用的,conjecture 推测, price 代价
  • 高科技的现代化世界可能不会诞生如果没有 计算机的发展。从机密的政府文件到银行与私人家用账户的交易,用于储存和处理数据的各种类型和尺寸的计算机的使用遍布社会。通过自动化技术计算机已打开了一个制造业的新纪元,并且它们提高了现代通信系统。它们是几乎每个研究领域 和应用技术领域的不可或缺的 工具,从建造宇宙模型 作出第二天的天气预报,它们的使用打开了新的猜想领域。数据库服务和计算机网络使得各种各样的信息源可获取。同样提高的技术也让对个人与企业隐私的入侵变得可能。计算机犯罪已经成为众多风险之一,这是现代化技术的代价之一。

The first adding machine, a precursor of the digital computer, was devised in 1642 by the French scientist, mathematician, and philosopher Blaise Pascal². This device employed a series of ten-toothed wheels, each tooth representing a digit from 0 to 9. The wheels were connected so that numbers could be added to each other by advancing the wheels by a correct number of teeth. In the 1670s the German philosopher and mathematician Gottfried Wilhelm Leibniz³ improved on this machine by devising one that could also multiply.

  • The first adding machine 第一台加法器,precursor 先驱,advancing the wheels 推动轮子
  • 第一台加法器,是数字计算机的先驱,由法国科学家数学家、哲学家布莱斯·帕斯卡于1642年设计出。该装置应用了一系列有十个齿的齿轮 ,每个齿表示0到9的数字。齿轮 之间相连因此每个数字能做加法通过将齿轮转动相应的齿数。在1670年,德国哲学家、数学家戈特弗里德·威廉·莱布尼茨通过设计了一个能乘的装置来改进该装置。

The French inventor Joseph-Marie Jacquard, in designing an automatic loom, used thin, perforated wooden boards to control the weaving of complicated designs. During the 1880s the American statistician Herman Hollerith³ conceived the idea of using perforated cards, similar to Jacquard's boards, for processing data. Employing a system that passed punched cards over electrical contacts, he was able to compile statistical information for the 1890 United States census.

  • wooden boards 木板,weaving 编织/交织,perforated card 打孔卡片,punched cards 穿孔卡片,electrical contact 电触点
  • 法国发明家约瑟夫-玛丽·雅卡 设计了一个自动化的织机 ,使用了薄的 穿孔的木板来控制复杂图案 的编织。19世纪80年代, 美国统计学家赫尔曼·何勒里想出了使用打孔卡片的主意,和雅卡的木板相似,用于处理数据。他使用了一个 穿孔卡片 电触点上划过的系统,他用于编译统计学数据在1890年美国的人口普查中。
相关推荐
Purple Coder1 小时前
基于人工智能的股票心态文章
学习
承渊政道2 小时前
Linux系统学习【深入剖析Git的原理和使用(上)】
linux·服务器·git·学习
凉、介2 小时前
文件系统(一)——分区表
笔记·学习·嵌入式
happymaker06262 小时前
Java学习日记——DAY24
学习
今儿敲了吗2 小时前
19| 海底高铁
c++·笔记·学习·算法
Asher阿舍技术站2 小时前
【AI基础学习系列】三、LLM基础知识
人工智能·学习·llm
丝斯20112 小时前
AI学习笔记整理(70)——AI+CAE
人工智能·笔记·学习
三万棵雪松3 小时前
【Linux Shell 编程基础学习与实践作业】
linux·运维·网络·学习·嵌入式linux
会算数的⑨3 小时前
Spring AI Alibaba 学习(三):Graph Workflow 深度解析(下篇)
java·人工智能·分布式·后端·学习·spring·saa