Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //經過ㄌㄅㄑ的指導發現似乎是hash寫爛後決定再試最後一次OuO
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- #define endl '\n'
- #define int long long
- int _hash(string str) {
- int result=0, num;
- result += (str[0] - 'A');
- for(int i=1; i<str.length(); i++) {
- result *= 10;
- result += (str[i] - '0');
- }
- return result;
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n, m, target;
- string input;
- cin >> n >> m;
- int data[n];
- for(int i=0; i<n; i++) {
- cin >> input;
- data[i] = _hash(input);
- }
- sort(data, data+n);
- for(int i = 0; i < m; i++) {
- bool ans = 0;
- cin >> input;
- target = _hash(input);
- int L = 0, R = n - 1;
- int M = (L+R)/2;
- while (L <= R) {
- M = (L + R) >> 1;
- if(data[M] == target) {
- ans = 1;
- break;
- }
- else if(data[M] > target) {
- R = M - 1;
- }
- else {
- L = M + 1;
- }
- }
- if(ans) cout << "Yes" << endl;
- else cout << "No" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement