找最小数
来源:互联网 发布:百度云盘vip破解版mac 编辑:程序博客网 时间:2024/05/16 18:02
- 题目描述:
第一行输入一个数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
- 来源:
- 2010年北京邮电大学计算机研究生机试真题
内存:920Kb, 耗时:10ms
#include<stdio.h> int n, arr[1005][2]; int main() { int i; while(scanf("%d", &n) != EOF) { for(i = 0; i < n; i++) { scanf("%d %d", &arr[i][0], &arr[i][1]); } int min_index = 0; for(i = 0; i < n; i++) { if(arr[i][0] < arr[min_index][0]) { min_index = i; } else if(arr[i][0] == arr[min_index][0] && arr[i][1] < arr[min_index][1]) { min_index = i; } } printf("%d %d\n", arr[min_index][0], arr[min_index][1]); } return 0;} /************************************************************** Problem: 1170 User: wusuopuBUPT Language: C Result: Accepted Time:10 ms Memory:920 kb****************************************************************/
更好的方法:内存:912kb, 耗时0ms
#include<stdio.h>int main() { int n, x, y, tempx, tempy; while(scanf("%d", &n) != EOF) { scanf("%d", &x); scanf("%d", &y); while(-- n) { scanf("%d", &tempx); scanf("%d", &tempy); if(tempx < x || tempx == x && tempy < y) {x = tempx; y = tempy;} } printf("%d %d\n", x, y); } return 0;}/************************************************************** Problem: 1170 User: kaoyanasi Language: C Result: Accepted Time:0 ms Memory:912 kb****************************************************************/
0 0
- 找最小数
- 题目1170:找最小数
- 题目1170:找最小数
- 找差值最小的数
- 题目1170:找最小数
- 题目1170:找最小数
- 题目1170:找最小数
- 题目1170:找最小数
- 题目1170:找最小数
- 九度oj1170:找最小数
- 九度OJ 1170 找最小数
- 找第K个最小数
- 九度 OJ 1170:找最小数
- 九度OJ 题目1170:找最小数
- 百度笔试题:找最小的不重复数
- SDUT 1480 哈希,找次数最多且数最小的
- leetcode 找旋转数组中最小的数
- A题之找K个最小的数
- 搜索优化之友好的网页设计制作
- Linux内核 hlist_head/hlist_node结构解析
- 2013 成长的一年
- MFC判断内存泄露的简单方法 CmemoryState
- 开始写博客
- 找最小数
- 关于EXTJS的decode和encode!!
- 跟随滚动条漂浮的返回顶部按钮效果
- SecureCRT home,end,delete 键不起作用问题解决
- Spring3 MVC Static Pages Example之四静态页面向学习笔记
- servlet基础
- mysql基础知识
- 如何做一个针对百度搜索引擎友好的网站
- 父母最坏与最好的五句话