Can you find it? (三分搜索
2017-04-20 16:02
246 查看
Can you find it? |
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others) |
Total Submission(s): 1199 Accepted Submission(s): 383 |
Problem DescriptionGive you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+Bj+Ck = X. |
InputThere are many cases. Every data case is described as followed: In the first line there are three integers L, N, M, in the second line there are L integers represent the sequence A, in the third line there are N integers represent the sequences B, in the forthline there are M integers represent the sequence C. In the fifth line there is an integer S represents there are S integers X to be calculated. 1<=L, N, M<=500, 1<=S<=1000. all the integers are 32-integers. |
OutputFor each case, firstly you have to print the case number as the form "Case d:", then for the S queries, you calculate if the formula can be satisfied or not. If satisfied, you print "YES", otherwise print "NO". |
Sample Input3 3 31 2 31 2 31 2 331410 |
Sample OutputCase 1:NOYESNO |
#include <iostream>#include <algorithm>#include <string.h>#include <cmath>#include <stdio.h>#include <vector>#include <map>#include <queue>#include <utility>typedef long long ll;using namespace std;struct Point {double x, y;Point(double x = 0.0, double y = 0.0):x(x), y(y){}Point& operator = (const Point& p) {this->x = p.x;this->y = p.y;return *this;}};Point A, B, C, D;int P, Q, R;Point Get_Point (const Point& x, const Point& y) {return Point((x.x + y.x)/2.0, (x.y + y.y)/2.0);}double Get_Len (const Point& x,const Point& y) {return sqrt((x.x - y.x)*(x.x - y.x) + (x.y - y.y)*(x.y - y.y));}double Get_Time (const Point& p) {Point left = C, right = D, mid, mmid;double mid_time = 0, mmid_time = 1;while (fabs(mmid_time - mid_time) > 1e-6) {mid = Get_Point(left, right);mmid = Get_Point(mid, right);mid_time = Get_Len(p, mid)/R + Get_Len(D, mid)/Q;mmid_time = Get_Len(p, mmid)/R + Get_Len(D, mmid)/Q;if (mid_time - mmid_time >= 1e-6)left = mid;elseright = mmid;}return mid_time + Get_Len(A, p)/P;}int main () {int T;cin >> T;while (T--) {cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> D.x >> D.y >> P >> Q >> R;Point left(A.x, A.y), right(B.x, B.y);double mid_time = 0, mmid_time = 1;while (fabs(mid_time - mmid_time) > 1e-6) {Point mid = Get_Point(left, right);Point mmid = Get_Point(mid, right);mid_time = Get_Time(mid);mmid_time = Get_Time(mmid);if (mid_time - mmid_time >= 1e-6)left = mid;elseright = mmid;}printf("%.2lf\n", mid_time);}}
相关文章推荐
- HDOJ 题目2141 Can you find it?(二分搜索)
- CSU-ACM2017暑假集训2-二分搜索 A - Can you find it?
- HDU2141 Can you find it?(搜索,二分)
- 简单搜索练习(一)二分入门 HDU 2141 Can you find it?POJ 2785 4 Value whose Sum is 0
- HDOJ 2141 Can you find it?(二分搜索的优化+总结)
- Can you find it? --CSU-ACM2017暑假集训2-二分搜索
- HDU - 2141:Can you find it?(二分搜索)
- HDU 2141 Can you find it?
- HDU2141:Can you find it?(二分 + 优化)
- HDU 2141 Can you find it?(二分)
- HDU - 2141 Can you find it?
- Can you find it? (二分)
- HDU 2141 can you find it?
- HDU 2141 Can you find it?(二分)
- HDU 2141 Can you find it?
- Can you find it? hdu2141 二分查找
- HDU2141——二分——Can you find it?
- HDU 2141 Can you find it?
- hdu_2141_Can you find it?(二分)
- hdu 2141 Can you find it? 二分