Where is the Marble? -UVA 10474
来源:互联网 发布:加强网络舆情管理通知 编辑:程序博客网 时间:2024/06/05 05:21
题目:uva10474
水题 ,存入后排序,寻找第一个等于x值得位置。
代码如下:
#include<iostream>#include<set>#include<iterator>#include<string>#include<set>#include<typeinfo>#include<queue>#include<list>#include<algorithm>#include<cstdio>#include<cctype>#include<cstring>#include<map>#include<vector>#include<cstdlib>#include<cmath>#include<stack>#include<sstream>#include<iomanip>const int maxn = 10000;using namespace std; int test;int main(){ vector<int> a; int n,m; int kase = 0; while(scanf("%d%d",&n,&m)==2&&n) { int tmp; a.clear(); for(int i =0;i<n;i++){ scanf("%d",&tmp); a.push_back(tmp); } sort(a.begin(),a.end()); printf("CASE# %d:\n",++kase); for(int i=0;i<m;i++) { int j; scanf("%d",&test); for(j=0;j<a.size();j++) if(test==a[j]) { printf("%d found at %d\n",test,j+1); break; } if(j==a.size()) printf("%d not found\n",test); } }}按照入门经典 可以用 lower_bound 函数
lower_bound 和 upper_bound 函数:
1 lower_bound 寻找 x最少能插入哪个位置
2 upper_bound寻找 x最大能插入那个位置
#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){ int a[15]; for(int i= 0;i<10;i++) a[i]=i+1; int p=lower_bound(a,a+10,3)-a; int q=upper_bound(a,a+10,3)-a; cout<<p<<endl<<q<<endl;}
0 0
- 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?
- uva 10474 - Where is the Marble
- Java多线程机制
- 职责链模式
- 关于自定义dialog
- Mybatis3.x与Spring4.x整合
- DB9串行接口
- Where is the Marble? -UVA 10474
- 动态规划初步( 01 背包、完全背包、多重背包)
- 产品研发
- 算法设计方法:递归的内涵与经典应用
- NBUT
- 解决nginx负载均衡的session共享问题
- 本地包含配合文件上传
- 配置一个Lua工程(支持命令行运行 和 vs断点调试)
- Android检查当前网络状态是否可用并