Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5199
Given the height of the bird in the tree, and the height of the shot, ask each shot to shoot the number of birds
In the game when this code is AC, to Hangzhou Electric has been the tle .... Hope that the heart of the people can point to the guidance. Busy in Snatch also ~ ~ ~
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <vector>6#include <algorithm>7 using namespacestd;8 9 Const intMAXN = 1e6 +5;Ten intVIS[MAXN]; Onevector<int>:: iterator P1, p2; Avector<int>h; - - intMain () the { - #ifndef Online_judge -Freopen ("In.txt","R", stdin); - #endif //Online_judge + - intN, M, q, HI; + while(SCANF ("%d%d", &n, &m)! =EOF) { A h.clear (); at for(inti =0; I < n; i++) { -scanf"%d", &hi); - h.push_back (HI); - } - - sort (H.begin (), H.end ()); inmemset (Vis,0,sizeof(Vis)); - for(inti =0; I < m; i++) { toscanf"%d", &q); +P1 =Lower_bound (H.begin (), H.end (), q); -P2 =Upper_bound (H.begin (), H.end (), q); the intpos = P1-H.begin (); * intPOS1 = P2-H.begin (); $ if(POS1 <= n && pos <= n && pos1! =POS) {Panax Notoginseng intT1 = H[pos], t2 =H[POS1]; - if(T1 = =q) { the if(!Vis[pos]) { +printf"%d\n", pos1-POS); AVis[pos] =1; the } + Else -printf"0\n"); $ } $ } - Else -printf"0\n"); the } - }Wuyi return 0; the}
BestCoder36 1002.Gunner Problem Solving report