您的位置:首页 > 其它

UVa 10474 - Where is the Marble?

2014-05-20 20:08 337 查看
白书上把这个题分类为回溯法,但我觉得就是暴力啊

题意是:给出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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: