uva 10474 - Where is the Marble?
2019独角兽企业重金招聘Python工程师标准>>>
太简单了没啥好说的,排下序然后搜索下,看不出要怎么用回溯法。
#include<stdio.h>
#include<stdlib.h>#define MAX 10005int marbles[MAX];int cmp( const void*a, const void*b) {return *(int*) a - *(int*) b;
}int search(int n, int q) {int i;for (i = 0; i < n; i++)if (marbles[i] == q)return i + 1;return -1;
}int main() {int n, q;int query, idx;int cases = 1;while (scanf("%d%d", &n, &q)) {if (n == 0)break;int i;for (i = 0; i < n; i++)scanf("%d", &marbles[i]);qsort(marbles, n, sizeof(int), cmp);printf("CASE# %d:\n", cases++);for (i = 0; i < q; i++) {scanf("%d", &query);idx = search(n, query);if (idx == -1) {printf("%d not found\n", query);} else {printf("%d found at %d\n", query, idx);}}}return 0;
}
转载于:https://my.oschina.net/jdflyfly/blog/283604
uva 10474 - Where is the Marble?相关推荐
- UVA 10474 Where is the Marble
题目描述: Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written ...
- 大理石在哪里?(Where is the Marble?,UVa 10474 )
大理石在哪里?(Where is the Marble?,UVa 10474 ) Raju and Meena love to play with Marbles. They have got a l ...
- 《算法竞赛入门经典》 例题5-1 大理石在哪(Where is the Marble,UVa 10474)
原题及翻译 Raju and Meena love to play with Marbles. 拉朱和米娜喜欢玩弹珠. They have got a lot of marbles with numb ...
- 大理石在哪儿 (Where is the Marble?,UVa 10474)
题目描述:算法竞赛入门经典例题5-1 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 ...
- 10474 - Where is the Marble?
排序,检索: 使用 bsearch 的 cmp 不能只返回 -1 或 1 (可能是要用差进行比较): # include <stdio.h> # include <stdlib.h& ...
- UVA - 10474
第五章的第一个大理石的题,附上书上的代码 #include<cstdio> #include<algorithm> using namespace std; const int ...
- 很有趣的STL初学资料
1.泛型程序设计简介与迭代器的介绍 2.常见的STL容器及其例题应用(UVA10474,UVA101,UVA10815,UVA156,UVA540,UVA136 HDU1027,CF501B,HDU1 ...
- 紫书《算法竞赛入门经典》
紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...
- 算法竞赛入门经典(第2版)—第五章(C++与STL入门)
文章目录 零碎知识点整理 题目 10474 - Where is the Marble? 101 - The Blocks Problem 10815 - Andy's First Dictionar ...
- ICPC训练联盟2021寒假冬令营(7)_2021.01.26_笔记
文章目录 试题链接 学习笔记 - C++STL.贪心算法 C++STL 迭代器 STL算法 关联式容器 贪心算法 介绍 使用贪心法能否得到最优解,是必须加以证明的. 体验贪心法内涵的实验范例 贪心法的 ...
最新文章
- 我国拟开展2016年新型智慧城市评价工作
- 从创作工具到虚拟超现实主义,聊一聊VR的艺术王国
- Ubuntu 16.04 Spark单机环境搭建
- Windows 10封装中出现“无法验证你的Windows安装”错误解决方法
- [Leedcode][JAVA][第445题][链表][栈]
- 毕设题目:Matlab元胞自动机交通流
- [文档]. FGD - FAT32文件系统详解
- 个人博客如何申请ICP备案
- SAP ABAP内表OCCURS,WORK AREA等 语法对比!
- Springboot测试类之@RunWith注解
- pve万兆网卡驱动_PVE+lede+DSM网卡硬盘直通+win10
- 文献阅读:利用斯托克斯参量验证光波的偏振态
- 向量点积衡量相似度_余弦距离、欧氏距离和杰卡德相似性度量的对比分析
- 微信支付异常(“应答的微信支付签名验证失败“)记录
- 五、T100固定资产之固定资产盘点管理篇
- 20 多个国外优秀Android开源 App ,值得收藏和学习
- 米洛个人修炼术:如何倍增你的功力修行速度达成健康体魄
- 单片机电梯上下行_为什么未来的电梯会移动得不仅仅是上下。
- 斑马条码打印机断电重启后无法打印问题
- Day 13 JUSTICE