UVa 10474 where is marble?
来源:互联网 发布:淘宝商品优惠券 编辑:程序博客网 时间:2024/06/03 19:06
题目二 UVa 10474 where is marble?
题目说的很复杂,但明白了就是很简单的问题。 有N块大理石,每个大理石上面有一个非负整数。(将大理石上的数按照从小到大排序后)有Q个问题,每一个问题输入一个非负整数,如果大理石上有这个数,则要输出第几块大理石 如果没有就输出没有找到这个数,输入多次问题。
代码如下:
#include<iostream>#include<algorithm>using namespace std;const int MAXN=10000;int marble[MAXN];int questnum[MAXN];int n,q;int main(){ int k=0; while(cin>>n>>q&&(n!=0||q!=0)) { int x; int flag=0; for(int i=0; i<n; i++) cin>>marble[i]; sort(marble,marble+n); // 对大理石进行排序 cout<<"CASE# "<<++k<<":"<<endl; while(q--) { cin>>x; int p=lower_bound(marble,marble+n,x)-marble; //lower_bound函数 查找大于或等于x的第一个位置 if(marble[p]==x) cout<<x<<" found at "<<p+1<<endl; //因为数组时从0开始的,而块数是从1开始数,所以要+1 else cout<<x<<" not found"<<endl; } } return 0;}
阅读全文
0 0
- UVa 10474 where is marble?
- UVa 10474 Where is the Marble?
- Uva 10474 Where is the Marble?
- uva 10474 Where is the Marble?
- UVA 10474 Where is the Marble?
- UVA 10474 - Where is the Marble
- uva-10474 - Where is the Marble?
- uva 10474 - Where is the Marble?
- UVA 10474 - Where is the Marble?
- UVa 10474 - Where is the Marble?
- UVa 10474 - Where is the Marble
- UVa 10474 - Where is the Marble?
- UVA 10474 Where is the Marble?
- UVA 10474 - Where is the Marble
- UVa - 10474 - Where is the Marble?
- uva 10474 Where is the Marble?
- uva 10474 Where is the Marble?
- uva - 10474 - Where is the Marble?
- (原创分享C# MVC)微信支付之公众号支付教程
- Spring使用Java类定义Bean信息
- fork调用
- 你不知道的产品分析法则
- 【笔记】PackageManager获取App基本信息实现Apk导出、分享、卸载
- UVa 10474 where is marble?
- Host is not allowed to connect to this MySQL server解决方法
- php对xml的XPath操作
- java学习(9) 匿名内部类
- 树状数组 区间修改区间求和总结
- Qt 调用 Windows 接口实现窗口置顶
- 开灯问题
- 四个Fragment相互切换界面,底部几个TextView点击切换相互切换界面
- 用git上传代码代码到github仓库