-
Notifications
You must be signed in to change notification settings - Fork 1
/
10474 - Where is the Marble?.cpp
105 lines (89 loc) · 1001 Bytes
/
10474 - Where is the Marble?.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*input
10 5
1
1
3
5
7
1
3
9
120
1
1
3
120
7
1234
10 12
1111
1111
1111
5
5
5
10
11
12
10
1111
5
10
11
12
1111
134
567
246
24
12
435
0 0
*/
#include <stdio.h>
#include <algorithm>
using namespace std;
int arr[10000];
int m, q;
int c = 0;
int binarys(int n, int up , int low)
{
int mid = (up + low)/2;
while ( up >= low)
{
if ( n == arr[mid])
{
while (mid >=0 && arr[mid-1] == arr[mid])
mid--;
return mid;
}
else if ( n > arr[mid])
low = mid + 1;
else
up = mid - 1;
mid = (low + up)/2;
}
return -1;
}
int main()
{
while ( true)
{
scanf("%d %d", &m , &q);
if ( m == 0 && q == 0) break;
printf("CASE# %d:\n", ++c);
for ( int i = 0 ; i < m ; i++)
scanf("%d", &arr[i]);
sort( arr , arr+m);
for ( int i = 0 ; i < q ; i++)
{
int n;
scanf("%d" , &n);
int tmp = binarys(n , m, 0);
if ( tmp == -1)
printf("%d not found\n", n);
else
printf("%d found at %d\n", n , tmp+1);
}
}
}