Portal: Click to open link
Main topic:
There are 2 teams playing basketball, and then tell you, a team voted n times blue, the distance between the B team voted M basket, the distance.
As we all know, basketball has a three-point line, and then lets you find a three-point line out, so that team a score-B team scored the most. When the difference is the same, find the biggest score.
2 points on the line.
Problem Solving Ideas:
Suppose a shot line. At x it is easy to figure out the score of each team. (You just need to sort and then two points which values are less than equals to him).
So just enumerate the shot lines and just enumerate between the n+m numbers. Then add a 0 and INF 2 lines.
Let's summarize:
After playing Guangzhou has not engaged in ACM, so long time did not write code, code is really the more the more ugly writing. After the end of the reading, I thought of the problem of thinking, wrote for 30 minutes.
#include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include < Cstring>using namespace Std;long long A1[201010],a2[201010];int main () {Long long n,m; CIN >> N; For (long long i = 1;i <= n;i++) {scanf ("%i64d", &a1[i]); } cin >> m; For (long long i = 1;i <= m;i++) {scanf ("%i64d", &a2[i]); } sort (a1+1,a1+1+n); Sort (a2+1,a2+1+m); Long Long ans1,ans2,temp1,temp2; Long long x, y; x = Upper_bound (a1+1,a1+1+n,0)-a1-1; y = Upper_bound (a2+1,a2+1+m,0)-a2-1; ans1 = 3ll*n-x; Ans2 = 3ll*m-y; For (long long i = 1;i <= n;i++) {x = Upper_bound (a1+1,a1+1+n,a1[i])-a1-1; y = Upper_bound (a2+1,a2+1+m,a1[i])-a2-1; Temp1 = 3ll*n-x; Temp2 = 3ll*m-y; if (Temp1-temp2 > Ans1-ans2) {ans1 = Temp1; Ans2 = Temp2; } if (temp1-temp2 = = ans1-ans2) {if (Temp1 > ans1) {ans1 = Temp1; Ans2 = Temp2; }}} for (long long i = 1;i <= m;i++) {x = Upper_bound (a1+1,a1+1+n,a2[i])-a1-1; y = Upper_bound (a2+1,a2+1+m,a2[i])-a2-1; Temp1 = 3ll*n-x; Temp2 = 3ll*m-y; if (Temp1-temp2 > Ans1-ans2) {ans1 = Temp1; Ans2 = Temp2; } if (temp1-temp2 = = ans1-ans2) {if (Temp1 > ans1) {ans1 = Temp1; Ans2 = Temp2; }}} x = Upper_bound (a1+1,a1+1+n,0x3f3f3f3f)-a1-1; y = Upper_bound (a2+1,a2+1+m,0x3f3f3f3f)-a2-1; Temp1 = 3ll*n-x; Temp2 = 3ll*m-y; if (Temp1-temp2 > Ans1-ans2) {ans1 = Temp1; Ans2 = Temp2; } if (temp1-temp2 = = ans1-ans2) {if (Temp1 > ans1) {ans1 = Temp1; Ans2 = Temp2; }} cout<<ans1<< ":" <<ans2<<endl; return 0;}
Codeforces 493C Vasya and Basketball (two points)