九度OJ&北邮机试题(2010计算机)

题目一、九度OJ-1169:比较奇偶数个数

http://ac.jobdu.com/problem.php?pid=1169

题目描述:

第一行输入一个数,为n,第二行输入n个数,这n个数中,如果偶数比奇数多,输出NO,否则输出YES。

输入:

输入有多组数据。

每组输入n,然后输入n个整数(1<=n<=1000)。

输出:

如果偶数比奇数多,输出NO,否则输出YES。

样例输入:
5
1 5 2 4 3
样例输出:
YES

直接来代码:

AC代码:

/**
  *@xiaoran
  */
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cmath>
#define LL long long
using namespace std;
int main()
{
	int a,even,odd,n;
	while(cin>>n){
        even=odd=0;
        for(int i=0;i<n;i++){
            cin>>a;
            if(a%2) even++;
            else odd++;
        }
        if(odd>even) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
	}
	return 0;
}

题目二、九度OJ-1170:找最小数

http://ac.jobdu.com/problem.php?pid=1170

题目描述:

第一行输入一个数n,1 <= n <= 1000,下面输入n行数据,每一行有两个数,分别是x y。输出一组x y,该组数据是所有数据中x最小,且在x相等的情况下y最小的。

输入:

输入有多组数据。

每组输入n,然后输入n个整数对。

输出:

输出最小的整数对。

样例输入:
5
3 3
2 2
5 5
2 1
3 6
样例输出:
2 1

不解释,AC代码

/**
  *@xiaoran
  *排序或者直接比较,排序O(nlogn),空间O(2n),直接O(n),空间O(1)
  */
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cmath>
#define LL long long
using namespace std;
int main()
{
    int n,x,y,xmin,ymin;
    while(cin>>n){
        cin>>xmin>>ymin;
        for(int i=1;i<n;i++){
            cin>>x>>y;
            if(x<xmin){
                xmin=x; ymin=y;
            }
            if(x==xmin&&y<ymin){
                xmin=x; ymin=y;
            }
        }
        cout<<xmin<<" "<<ymin<<endl;
    }
	return 0;
}

题目三、九度OJ-1171:C翻转

http://ac.jobdu.com/problem.php?pid=1171

题目描述:

首先输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据。

操作类型有四种:

1 2 表示:90度,顺时针,翻转4个数

1 3 表示:90度,顺时针,翻转9个数

2 2 表示:90度,逆时针,翻转4个数

2 3 表示:90度,逆时针,翻转9个数

输入:

输入有多组数据。

每组输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据。

输出:

输出翻转后的数组。

样例输入:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
1 3 1 1
样例输出:
11 6 1 4 5
12 7 2 9 10
13 8 3 14 15
16 17 18 19 20
21 22 23 24 25

题目分析:

二维数组模拟的问题,仔细想都能搞定。

AC代码:

#include<iostream>
#include<cstring>
using namespace std;
int a[10][10],b[10][10];
//ok表示旋转方式,x,y,表示旋转数组的左上角下标,k表示旋转个数
void XuanZhuan(int ok,int k,int x,int y){
    memcpy(b,a,sizeof(a));
    if(ok==2){//逆时针旋转
        int ky,kx=x;
        for(int j=y;j<y+k;j++){
            ky=y;
            for(int i=x+k-1;i>=0;i--){
                a[i][j]=b[kx][ky++];
            }
            kx++;
        }
    }
    else if(ok==1){//顺时针旋转
        int ky,kx=x+k-1;
        for(int j=y;j<y+k;j++){
            ky=y;
            for(int i=x;i<x+k;i++){
                a[i][j]=b[kx][ky++];
            }
            kx--;
        }
    }
}

int main()
{
    int ok,k,x,y;
    while(cin>>a[1][1]){
        for(int i=1;i<=5;i++){
            for(int j=1;j<=5;j++){
                if((i+j)!=2) cin>>a[i][j];
            }
        }
        cin>>ok>>k>>x>>y;
        XuanZhuan(ok,k,x,y);
        for(int i=1;i<=5;i++){
            for(int j=1;j<=5;j++){
                if(j!=5) cout<<a[i][j]<<" ";
                else cout<<a[i][j]<<endl;
            }
            //cout<<endl;
        }

    }
    return 0;
}

题目四、九度OJ-1172:哈夫曼树

http://ac.jobdu.com/problem.php?pid=1172

题目描述:

哈夫曼树,第一行输入一个数n,表示叶结点的个数。需要用这些叶结点生成哈夫曼树,根据哈夫曼树的概念,这些结点有权值,即weight,题目需要输出所有结点的值与权值的乘积之和。

输入:

输入有多组数据。

每组第一行输入一个数n,接着输入n个叶节点(叶节点权值不超过100,2<=n<=1000)。

输出:

输出权值。

样例输入:
5
1 2 2 5 9
样例输出:
37

题目分析:

可以建立哈弗曼树,但是题目只让求权值,直接上优先队列就行了,当然也可以排序,因为数据太少,怎么都行。

AC代码:

/**
  *@xiaoran
  *优先队列
  */
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cmath>
#define LL long long
using namespace std;
int main()
{
    int n;
    while(cin>>n){
        priority_queue<int, vector<int>,greater<int> >  p;
        int ans=0,x;
        for(int i=0;i<n;i++){
            cin>>x;
            p.push(x);
        }
        while(p.size()>1){
            int a=p.top();
            p.pop();
            int b=p.top();
            p.pop();
            ans+=a+b;
            p.push(a+b);
        }
        cout<<ans<<endl;
    }
	return 0;
}
时间: 2024-08-05 07:09:14

九度OJ&北邮机试题(2010计算机)的相关文章

九度OJ&amp;北邮机试题题解(北邮2010网院)

题目一.九度OJ-1173:查找(水题随便搞) ac.jobdu.com/problem.php?pid=1173 题目描述: 输入数组长度 n 输入数组      a[1...n] 输入查找个数m 输入查找数字b[1...m] 输出 YES or NO  查找有则YES 否则NO . 输入: 输入有多组数据. 每组输入n,然后输入n个整数,再输入m,然后再输入m个整数(1<=m<=n<=100). 输出: 如果在n个数组中输出YES否则输出NO. 样例输入: 5 1 5 2 4 3 3

九度OJ&amp;北邮机试题(2011网院)

题目一.九度OJ-1177:查找 http://ac.jobdu.com/problem.php?pid=1177 题目描述: 读入一组字符串(待操作的),再读入一个int n记录记下来有几条命令,总共有2中命令:1.翻转  从下标为i的字符开始到i+len-1之间的字符串倒序:2.替换  命中如果第一位为1,用命令的第四位开始到最后的字符串替换原读入的字符串下标 i 到 i+len-1的字符串.每次执行一条命令后新的字符串代替旧的字符串(即下一条命令在作用在得到的新字符串上). 命令格式:第一

九度oj 1002 Grading 2011年浙江大学计算机及软件工程研究生机试真题

1 #include<iostream> 2 #include<queue> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 int map[15][15]; 9 int main(){ 10 int P,T,G1,G2,G3,GJ; 11 while(cin>>P

九度oj 1004 Median 2011年浙江大学计算机及软件工程研究生机试真题

题目1004:Median 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:14162 解决:3887 题目描述: Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 1

九度oj 1032 ZOJ 2009年浙江大学计算机及软件工程研究生机试真题

题目1032:ZOJ 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4102 解决:2277 题目描述: 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出. 输入: 题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束.1<=length<=100. 输出: 对于每组输入,请输出一行,表示按照要求处理后的字符串.具体可见样例. 样例输入: ZZOOOJJJ ZZZZOOOOO

九度oj 1468 Sharing 2012年浙江大学计算机及软件工程研究生机试真题

题目1468:Sharing 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2687 解决:550 题目描述: To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix.

[ACM] 九度OJ 1553 时钟

时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1733 解决:656 题目描述: 如图,给定任意时刻,求时针和分针的夹角(劣弧所对应的角). 输入: 输入包含多组测试数据,每组测试数据由一个按hh:mm表示的时刻组成. 输出: 对于每组测试数据,输出一个浮点数,代表时针和分针的夹角(劣弧对应的角),用角度表示,结果保留两位小数. 样例输入: 03:00 14:45 样例输出: 90.00 172.50 来源: 2014年王道论坛计算机考研机试全真模拟考试 解题思路: 求时针和分针的

九度oj 题目1007:奥运排序问题

九度oj 题目1007:奥运排序问题   恢复 题目描述: 按要求,给国家进行排名. 输入:                        有多组数据. 第一行给出国家数N,要求排名的国家数M,国家号从0到N-1. 第二行开始的N行给定国家或地区的奥运金牌数,奖牌数,人口数(百万). 接下来一行给出M个国家号. 输出:                        排序有4种方式: 金牌总数 奖牌总数 金牌人口比例 奖牌人口比例 对每个国家给出最佳排名排名方式 和 最终排名 格式为: 排名:排名

[ACM] 九度OJ 合唱队形 (最长递增子序列改版)

题目1131:合唱队形 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1680 解决:520 题目描述: N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学不交换位置就能排成合唱队形. 合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1, 2, -, K,他们的身高分别为T1, T2, -, TK, 则他们的身高满足T1 < T2 < - < Ti , Ti > Ti+1 > - > TK (1 <= i <=