|
|
вернуться в форумtwo different solutions #include <cstdio> #include <map> std:: map <int, int> a; int n, m, q, i, x, ans; void solve(){ scanf("%d", &n); for(i = 0 ; i < n ; i ++) scanf("%d", &x), a[x] ++; scanf("%d", &m); for(i = 0 ; i < m ; i ++){ scanf("%d", &q); if(a[q]) ans ++; } printf("%d", ans); } int main(){ solve(); } Re: two different solutions #include <cstdio> #include <algorithm> int a[15051]; int n, m, q, i; int ans; int binary(){ int left = 0, right = n-1, middle; while(left <= right){ middle = (left + right) >> 1; if(a[middle] == q) return middle; if(a[middle] > q) right = middle - 1; if(a[middle] < q) left = middle + 1; } return -1; } void solve(){ scanf("%d", &n); for(i = 0 ; i < n ; i ++) scanf("%d", a + i); std:: sort(a, a + n); scanf("%d", &m); while(m --){ scanf("%d", &q); if(binary() != -1) ans ++; } printf("%d", ans); } int main(){ solve(); } Re: two different solutions Послано ELDVN 4 ноя 2015 00:37 Me too use the STL, its a simple and easy for write) And not more to time of run. 1.450 for map && 1.405 for binary_search.. |
|
|