UVa 10474 - Where is the Marble?
2014-05-20 20:08
337 查看
白书上把这个题分类为回溯法,但我觉得就是暴力啊
题意是:给出n, q,后面跟着n个数代表第i个石头上的数字a[i]
再给出q个数,让判断q个数在石头上是否出现,若出现输出found+位置,未出现输出not found
代码如下:
题意是:给出n, q,后面跟着n个数代表第i个石头上的数字a[i]
再给出q个数,让判断q个数在石头上是否出现,若出现输出found+位置,未出现输出not found
代码如下:
#include <cstdio> #include <iostream> #include <algorithm> #define MAXN 10010 #define ll long long using namespace std; int a[MAXN]; int b[MAXN]; int main(void) { int n, q, ques, T=1; while(cin >> n >> q, n&&q) { for(int i=1; i<=n; ++i) cin >> a[i]; sort(a+1, a+n+1); int ques; for(int i=0; i<q; ++i) { cin >> b[i]; } cout << "CASE# " << T++ << ":" << endl; for(int i=0; i<q; ++i) { int ok = 0; for(int j=1; j<=n; ++j) { if(a[j] == b[i]) { ok = 1; cout << b[i] << " found at " << j << endl; break; } } if(!ok) cout << b[i] << " not found" << endl; } } return 0; }
相关文章推荐
- UVa 10474 Where is the Marble? (二分查找&equal_range()的使用)
- 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?
- UVa10474 Where is the Marble?
- UVA10474 - 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?