Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >杭电2016年计算机复试真题

杭电2016年计算机复试真题

作者头像
EmoryHuang
发布于 2022-09-26 11:37:33
发布于 2022-09-26 11:37:33
31900
代码可运行
举报
文章被收录于专栏:EmoryHuang's BlogEmoryHuang's Blog
运行总次数:0
代码可运行

杭电 2016 年计算机复试真题

写在前面

此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!


第一题

Problem Description

判断一个数 N 是否是素数,是的话输出 “YES”,否则输出 “NO”

Input

输入包含多个测试实例,每行包含一个正整数

Output

若是的素数输出 “YES”,否则输出 “NO”

Sample Input

1000000007 100

Sample Output

YES NO

解题思路

整除或者打表

参考源码

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
//方法一:整除
#include <cmath>
#include <iostream>
using namespace std;
bool isprime(long long a) {
    if (a <= 1) return false;
    for (long long i = 2; i <= sqrt(a); i++) {
        if (a % i == 0) return false;
    }
    return true;
}
int main() {
    long long n;
    while (cin >> n) {
        if (isprime(n))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

//方法二:打表
#include <cstring>
#include <iostream>
using namespace std;
#define MAX 1000000
bool prime[MAX];
void findprime() {
    prime[0] = false;
    prime[1] = false;
    memset(prime, true, sizeof(prime));
    for (int i = 2; i < MAX; i++)
        if (prime[i])  //如果是素数
            for (int j = 2 * i; j < MAX; j += i) {
                prime[j] = false;  //筛去所有i的倍数
            }
}
int main() {
    int n;
    findprime();
    while (cin >> n) {
        if (prime[n])
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

第二题

Problem Description

在一个二维平面内有 n 个点,每个点坐标为(x,y),求最近的两点的距离

Input

输入首先是一个正整数,表示平面上点的个数,接下来是 n 行,分别是每个点的坐标(x,y)

Output

最近的两点的距离

Sample Input

5 1 2 100 200 1000 2000 1000 1 1 3

Sample Output

1

解题思路

暴力破解,计算每个点之间的距离

参考源码

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
struct node {
    int x, y;
} temp;
int main() {
    int n;
    double min = 0x3fffffff;
    vector<node> vt;
    while (cin >> n) {
        for (int i = 0; i < n; i++) {
            cin >> temp.x >> temp.y;
            vt.push_back(temp);
        }
        for (int i = 0; i < n - 1; i++) {  //遍历每个点
            for (int j = i + 1; j < n; j++) {
                double dis = sqrt(pow((vt[i].x - vt[j].x), 2) + pow((vt[i].y - vt[j].y), 2));
                if (min > dis) min = dis;
            }
        }
        cout << min << endl;
    }
    return 0;
}

第三题

Problem Description

有一个文件记录了学生期末考试的几门成绩和学号,求出这几门课程的平均分和总分,并按照总分排序,从高到底,如果成绩相同,按照学号从小到大的顺序。

Input

数据从文件读入。第一行是表头,接下来数行每一行表示一个学生的数据

Output

按照总分排序,从高到底,如果成绩相同,按照学号从小到大的顺序输出

Sample Input

姓名 学号 语文 数学 英语 A 1 20 40 40 B 2 30 39 31 C 3 99 5 5

Sample Output

B C A

解题思路

文件处理题,需要使用 fstream,另外注意表头的处理

参考源码

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <algorithm>
#include <cstring>
#include <fstream>
#include <iostream>
using namespace std;
struct student {
    char name[20], id[20];
    int a, b, c, d;
} stu[1000];
bool cmp(student m, student n) {
    if (m.a + m.b + m.c + m.d != n.a + n.b + n.c + n.d)
        return m.a + m.b + m.c + m.d > n.a + n.b + n.c + n.d;
    else
        return m.id < n.id;
}
int main() {
    int n = 0;
    fstream in;
    in.open("..\\HDU2016test\\student.txt", ios::in);
    if (!in) cout << "error" << endl;
    string s;
    getline(in, s);  //处理第一行
    while (!in.eof()) {
        in >> stu[n].name >> stu[n].id;
        in >> stu[n].a >> stu[n].b >> stu[n].c >> stu[n].d;
        n++;
    }
    in.close();  //文件关闭
    sort(stu, stu + n, cmp);
    for (int i = 0; i < n; i++) {
        if (i == 0)
            cout << stu[i].name;
        else
            cout << " " << stu[i].name;
    }
    cout << endl;
    return 0;
}

第四题

Problem Description

有一个由数字组成的二维矩阵,大小为 N*M;还有一个大小为 n*m 小二维矩阵,想象将小二维矩阵上面(小矩阵左上角位置和大矩阵某个位置对应放置),在不同的位置,这两个二维矩阵对应位置的数字绝对值之差的和一般是不同的,求这个绝对值之差的和的最小值,并求出对应的大矩阵位置

Input

输入首先是 N 与 M,接着是N*M的矩阵,之后是 n 与 m,接着n*m的小二维矩阵

Output

输出大矩阵与小矩阵对应元素绝对值差的和 s,并输出起始坐标

Sample Input

4 4 1 2 3 4 4 5 6 8 1 2 3 4 5 6 7 8 2 2 2 2 4 5

Sample Output

1 (1,1)

解题思路

把小矩阵放到大矩阵上一一计算,找到绝对值之差的和的最小值

参考源码

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <cmath>
#include <iostream>
using namespace std;
int map1[1000][1000];
int map2[1000][1000];
int main() {
    int N, M, n, m;
    int posi, posj, min;
    while (cin >> N >> M) {
        posi = posj = 0;
        min = 0x3fffffff;
        for (int i = 0; i < N; i++)
            for (int j = 0; j < M; j++) cin >> map1[i][j];
        cin >> n >> m;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) cin >> map2[i][j];
        for (int i = 0; i <= N - n; i++) {  // i,j为小矩阵起始位置
            for (int j = 0; j <= M - m; j++) {
                int temp = 0;
                for (int p = 0; p < n; p++) {
                    for (int q = 0; q < m; q++) {
                        temp += fabs(map1[i + p][j + q] - map2[p][q]);
                    }
                }
                if (min > temp) {
                    posi = i;
                    posj = j;
                    min = temp;
                }
            }
        }
        cout << min << " (" << posi + 1 << "," << posj + 1 << ")" << endl;
    }
    return 0;
}

相关内容

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-03-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
杭电2015年计算机复试真题
此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!
EmoryHuang
2022/09/26
4050
杭电2019年计算机复试真题
此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!
EmoryHuang
2022/09/26
2640
杭电2010年计算机复试真题
此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!
EmoryHuang
2022/09/26
2380
PAT 1025 PAT Ranking (25分) vector + sort
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.
vivi
2020/07/14
3540
杭电2017年计算机复试真题
此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!
EmoryHuang
2022/09/26
3720
杭电2018年计算机复试真题
此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!
EmoryHuang
2022/09/26
4150
杭电2014年计算机复试真题
此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!
EmoryHuang
2022/09/26
1790
杭电2012年计算机复试真题
此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!
EmoryHuang
2022/09/26
2220
杭电2011年计算机复试真题
此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!
EmoryHuang
2022/09/26
2430
杭电2013年计算机复试真题
此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!
EmoryHuang
2022/09/26
1890
杭电OJ2050-2059
我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是 n 条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成 7 部分,具体如右所示。
EmoryHuang
2022/09/26
3660
杭电OJ2050-2059
杭电OJ2090-2099
妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐。现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵。
EmoryHuang
2022/09/26
3210
杭电OJ2030-2039
对于每一段文本,输出其中的汉字的个数,每个测试实例的输出占一行。 [Hint:] 从汉字机内码的特点考虑~
EmoryHuang
2022/09/23
3760
杭电OJ2070-2079
Your objective for this question is to develop a program which will generate a fibbonacci number.The fibbonacci function is defined as such: f(0) = 0 f(1) = 1 f(n) = f(n-1) + f(n-2) Your program should be able to handle values of n in the range 0 to 50.
EmoryHuang
2022/09/26
2530
杭电OJ2070-2079
杭电OJ2080-2089
这次 xhd 面临的问题是这样的:在一个平面内有两个点,求两个点分别和原点的连线的夹角的大小。 注:夹角的范围[0,180],两个点不会在圆心出现。
EmoryHuang
2022/09/26
3110
杭电OJ2080-2089
杭电OJ2000-2009
输入数据有多组,每组占一行,由 4 个实数组成,分别表示 x1,y1,x2,y2, 数据之间用空格隔开。
EmoryHuang
2022/09/23
3840
杭电OJ2060-2069
background: Philip likes to play the QQ game of Snooker when he wants a relax, though he was just a little vegetable-bird. Maybe you hadn’t played that game yet, no matter, I’ll introduce the rule for you first. There are 21 object balls on board, including 15 red balls and 6 color balls: yellow, green, brown, blue, pink, black. The player should use a white main ball to make the object balls roll into the hole, the sum of the ball’s fixed value he made in the hole is the player’s score. The player should firstly made a red ball into the hole, after that he gains red-ball’s value(1 points), then he gets the chance to make a color ball, then alternately. The color ball should be took out until all the red-ball are in the hole. In other word, if there are only color balls left on board, the player should hit the object balls in this order: yellow(2 point), green(3 point), brown(4 point), blue(5 point), pink(6 point), black(7 point), after the ball being hit into the hole, they are not get out of the hole, after no ball left on board, the game ends, the player who has the higher score wins the game. PS: red object balls never get out of the hole. I just illustrate the rules that maybe used, if you want to contact more details, visit http://sports.tom.com/snooker/ after the contest. for example, if there are 12 red balls on board(if there are still red ball left on board, it can be sure that all the color balls must be on board either). So suppose Philp can continuesly hit the ball into the hole, he can get the maximun score is 12 × 1 (12 red-ball in one shoot) + 7 × 12(after hit a red ball, a black ball which was the most valuable ball should be the target) + 2 + 3 + 4 + 5 + 6 + 7(when no red ball left, make all the color ball in hole). Now, your task is to judge whether Philip should make the decision to give up when telling you the condition on board(How many object balls still left not in the hole and the other player’s score). If Philp still gets the chance to win, just print “Yes”, otherwise print “No”.
EmoryHuang
2022/09/26
3620
杭电OJ2060-2069
HDU 1874 畅通工程续 2008浙大研究生复试热身赛(2)
畅通工程续 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 79501 Accepted Submission(s): 30582
风骨散人Chiam
2020/10/28
3070
【计算机本科补全计划】CCF计算机职业资格认证 2017-03 试题初试
正文之前 我在之前的文章中提到过,我的老师要求我的CCF 考试考个280分来打个底,(没错,我就是那个横跨考研、工作、保研三大领域的男人)相当于是测试下我的能力,所以虽然不知道近期有没有相关的考试,但是我还是开始准备。这种等级考试,当然就是从刷题开始了!!至于什么大纲,什么宝典,见鬼去吧~ 不信这玩意,题海战术从小用到大,骨子里都习惯了。当然还是直接怼题目来得爽了 ~ ~ 而且还可以实践自己的各种知识积淀,自己看书看一遍,简书写笔记写一遍,最后写题写一遍,考试然后再被轮一遍,这么下来还没有十足长进我就不信了
用户1687088
2018/05/07
1.5K0
【计算机本科补全计划】CCF计算机职业资格认证 2017-03 试题初试
杭电OJ2040-2049
古希腊数学家毕达哥拉斯在自然数研究中发现,220 的所有真约数 (即不是自身的约数) 之和为: 1+2+4+5+10+11+20+22+44+55+110 = 284。 而 284 的所有真约数为 1、2、4、71、 142,加起来恰好为 220。人们对这样的数感到很惊奇,并称之为亲和数。 一般地讲,如果两个数中任何一个数都是另一个数的真约数之和,则这两个数就是亲和数。 你的任务就编写一个程序,判断给定的两个数是否是亲和数
EmoryHuang
2022/09/26
2800
杭电OJ2040-2049
相关推荐
杭电2015年计算机复试真题
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验