uva10474大理石在哪儿where is the marble?
来源:互联网 发布:sql截取日期的年月日 编辑:程序博客网 时间:2024/04/30 09:49
背景:做了这么久的题,唯一一道一次ac的,可见这道题是如何的简单。
思路:思路很清楚的模拟题,先排序再查找。
学习:sort函数和lower_bound函数,sort函数排序就不多说了,lower_bound函数作用是查找一个数组中大于等于x的第一个位置。
#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;int figue[10000];void print(int n,int b){ for(int i=0;i<n;i++) { if(figue[i]==b) {printf("%d found at %d\n",b,i+1);return;} if(figue[i]>b) {printf("%d not found\n",b);return;} } printf("%d not found\n",b); return;}int main(void){ int N,Q,k,game=1; while(cin>>N>>Q&&N&&Q) { printf("CASE# %d:\n",game++); for(int i=0;i<N;i++) cin>>figue[i]; sort(figue,figue+N); while(Q--) { cin>>k; print(N,k); } } return 0;}
0 0
- uva10474大理石在哪儿where is the marble?
- 《算法竞赛入门经典2ndEdition 》例题5-1 大理石在哪儿(Where is the marble?, Uva10474)
- 大理石在哪儿 where is the Marble? lower_bound()
- 大理石在哪儿 where is the Marble?
- UVa 10474 Where is the Marble?(大理石在哪儿)
- 10474 - 大理石在哪儿Where is the Marble?(排序+检索)
- uva 10474 Where is the Marble?(大理石在哪儿)
- 大理石在哪儿(Where is the marble?,UVa 10474)
- uva10474 - Where is the Marble?
- UVa10474 Where is the Marble?
- UVA10474-Where is the Marble?
- UVA10474 Where is the Marble?
- uva10474 - Where is the Marble?
- uva10474 Where is the Marble?
- uva10474 - Where is the Marble?
- UVA10474 Where is the Marble?
- UVA10474 Where is the Marble?
- UVA10474 Where is the Marble?
- vector函数
- UIAlertView&UIActionSheet
- cocos2dx学习日记三:menu创建
- android工程下assets与raw文件夹
- ThinkPHP学习笔记(一)
- uva10474大理石在哪儿where is the marble?
- android 事件分发 结论
- Shiro异常1:java.lang.IllegalArgumentException: Line argument must contain a key and a value. Only one
- nosql
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- POJ 2533 Longest Ordered Subsequence
- 优化网站加载速度的14个技巧
- 用NAT实现外网对内网服务器的访问
- Shadow DOM 与 HTML Templates