Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:超级大牛好In Reply To:这题hash怎么hash的?我二分查找都超时呢 Posted by:limingfei at 2007-07-20 21:34:02 > 代码: > #include <iostream> > #include <string> > #include <memory> > #include <algorithm> > using namespace std; > > const int maxn = 1000; > > struct node { > int x, y; > }list[maxn]; > int n; > > bool operator<(const node &a, const node &b) > { > return (a.x < b.x || (a.x == b.x && a.y < b.y)); > } > > bool init() > { > cin >> n; > if (!n) return false; > int i; > for (i = 0; i < n; ++i) { > cin >> list[i].x >> list[i].y; > list[i].x *= 2; > list[i].y *= 2; > } > sort(list, list + n); > return true; > } > > void run() > { > int tot = 0; > int i, j; > int a, b; > int x, y; > node t1, t2; > for (i = 0; i < n; ++i) { > for (j = i + 1; j < n; ++j) { > a = list[j].x - list[i].x; > b = list[j].y - list[i].y; > a /= 2; > b /= 2; > x = list[i].x + a; > y = list[i].y + b; > t1.x = x - b; > t1.y = y + a; > t2.x = x + b; > t2.y = y - a; > if (binary_search(list, list + n, t1) && binary_search(list, list + n, t2)) { > ++tot; > } > } > } > cout << tot / 2 << endl; > } > > int main(void) > { > while (init()) { > run(); > } > return 0; > } > > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator