1. 程式人生 > >Hard challenge HDU

Hard challenge HDU

思路:對所有的點進行極角座標排序,然後從最小的點開始,對每個點i,二分查詢它的極角逆時針旋轉180度的角,在所有點之間的位置。如果這個角座標的點是L右邊的是R,只要求當前點到L點的權值總和,再算R順時針轉到i的權重總和.(這裡用線段樹維護下)。然後兩個權重相乘就是當前直線的權值,然後總體取最大。

主要是要想到,對於n個點,做一條過原點的直線,將點集分為兩塊,這條直線的值就是,直線兩邊點權重總和乘得到的。然後去列舉這樣的直線就行了。

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <math.h>
using namespace std;
const int Max_N = 5*1e4+100;
#define M_PI1 3.141592653589793238462643383279502
int _sum, v;  
int sumv[4*Max_N];  
int l ,r , P;  
void updata(int o, int L, int R)  
{  
    int lc = o * 2, rc = o * 2 + 1;  
    int M = L + (R-L) / 2;  
    if (R == L) {  
        sumv[o] = v;  
    }  
    else {  
        if (P <= M) updata(o*2, L, M);  
        else updata(o*2+1, M+1, R);   
        sumv[o] = sumv[lc] + sumv[rc];  
    }  
}  

long long int query(int o, int L, int R)  
{  
	if (l > R || r < L) return 0;
    if (l <= L && r >= R) {  
       return sumv[o]; 
    }  
    else {  
        int M = L + (R - L) / 2;  
        return query(o*2, L, M) + query(o*2 + 1, M + 1, R);  
    }  
}  


struct point{
	int x, y, w;
	double t;
};
int T;
int n;
const double eps = 1e-6;  
bool cmp(const point &p1, const point &p2)
{
	return p1.t < p2.t - eps;
}
point p[Max_N];
int main()
{
	cin >> T;
	while (T--) {
		scanf("%d", &n);
		memset(sumv, 0, sizeof(sumv));
		for (int i = 1; i <= n; i++)
			scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].w);
		for (int i = 1; i <= n; i++)
			p[i].t = atan2(double(p[i].y), double(p[i].x));
		sort(p+1, p+1+n, cmp);
		for (int i = 1; i <= n; i++) {
			P = i;
			v = p[i].w;
			updata(1, 1, n);
		}
		long long int ans1 = 0;
		long long int ans2 = 0;
		long long int ans = 0;
		for (int i = 1; i <= n; i++) {
			double t2 = p[i].t + M_PI1;
			if (t2 > M_PI1 + eps) t2 = -(M_PI1-(t2-M_PI1));//取旋轉180的角。
			int l1 = 1; int r1 = n;
			if (t2 + eps < p[1].t || t2 > p[n].t + eps) {
				//cout << "ss" << endl;
				l = 1; r = i;
				ans1 = query(1, 1, n);
				l = i+1; r = n;
				if (l > n) ans2 = 0;
				else ans2 = query(1, 1, n);
				ans = max(ans, ans1 * ans2);

				l = 1; r = i-1;
				if (r <= 0) ans1 = 0;
				else ans1 = query(1, 1, n);
				l = i; r = n;
				ans2 = query(1, 1, n);
				ans = max(ans, ans1 * ans2);
			//	cout << ans << endl;
				continue;
			}
			while(true) {
				int mid = (l1 + r1) / 2;
				if (p[mid].t > t2 + eps) r1 = mid;
				else l1 = mid;
				if (l1 + 1 == r1) break;
			}

			if (r1 > i) {
				l = i; r = l1;
				ans1 = query(1, 1, n);
				l = r1; r = n;
				ans2 = query(1, 1, n);
				l = 1; r = i-1;
				if (l >= 1)
					ans2 += query(1, 1, n);
				ans = max(ans, ans1 * ans2);

				l = i+1; r = l1;
				if (l < r)
					ans1 = query(1, 1, n);
				else ans1 = 0;
				l = r1; r = n;
				ans2 = query(1, 1, n);
				l = 1; r = i;
				ans2 += query(1, 1, n);
				ans = max(ans, ans1 * ans2);
			}
			else {
				l = r1; r = i;
				ans1 = query(1, 1, n);
				l = i+1; r = n;
				if (l <= r)
					ans2 = query(1, 1, n);
				else ans2 = 0;
				l = 1; r = l1;
				ans2 += query(1, 1, n);
				ans = max(ans, ans1 * ans2);

				l = r1; r = i-1;
				if (l <= r) 
					ans1 = query(1, 1, n);
				else ans1 = 0;
				l = i; r = n;
				ans2 = query(1, 1, n);
				l = 1; r = l1;
				ans2 += query(1, 1, n);
				ans = max(ans, ans1 * ans2);
			}

		}
		printf("%lld\n", ans);
	}
	
	return 0;	
}


相關推薦

Hard challenge HDU

思路:對所有的點進行極角座標排序,然後從最小的點開始,對每個點i,二分查詢它的極角逆時針旋轉180度的角,在所有點之間的位置。如果這個角座標的點是L右邊的是R,只要求當前點到L點的權值總和,再算R順時針轉到i的權重總和.(這裡用線段樹維護下)。然後兩個權重相乘就是當前直線的

HDU 6127 Hard challenge (極角掃描)

sign eps +++ string vector -- comm opera val 題意:給定 n 個點,和權值,他們兩兩相連,每條邊的權值就是他們兩個點權值的乘積,任意兩點之間的直線不經過原點,讓你從原點劃一條直線,使得經過的直線的權值和最大。 析:直接進行極角掃描

hdu 6127 : Hard challenge (2017 多校第七場 1008)(計算幾何)

for %d logs opera log val r+ ++ show 題目鏈接 題意:二維平面上有n個點(沒有重疊,都不在原點,任意兩點連線不過原點),每個點有一個權值,用一條過原點的直線把他們劃分成兩部分,使兩部分的權值和的乘積最大。輸出最大的乘積。 極角排序後,將原

HDU 6127 Hard challenge【極角排序】

題目來戳呀 Problem Description There are n points on the plane, and the ith points has a value vali, and its coordinate is (xi,yi). It

hdu6127 Hard challenge

des score chm n-2 地址 hal for each iss output 地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6127 題目: Hard challenge Time Limit: 4000/

HDU6127-Hard challenge

HDU6127 原題傳送門 題意:給定n個平面座標點,任意兩個點兩兩連線(連線不過原點),每個點帶權值,然後任意兩個點所連成的線段的權值為點權的乘積,找一條過原點的直線,要求它所穿過的線段的權值和最大,輸出最大權值和 官方題解:對於一條直線,線段權值和實際上

2017 Multi-University Training Contest 10 1002 Array Challenge HDU 6172(找規律 矩陣快速冪)

題意:There’s an array that is generated by following rule.h0=2,h1=3,h2=6,hn=4hn−1+17hn−2−12hn−3−16And

人生第一個快速冪的題(HDU - 1097--A hard puzzle )

快速冪算法 pre namespace using str logs main ref cin 題意: 最簡單的快速冪。給你兩個數n和m,求n^m的最後一位; 解題思路: 額,快速冪就很簡單了,這裏只要最後一位可以一對每次運算都%10; 代碼: #include<c

第十場 hdu 6172 Array Challenge(矩陣快速冪)

不知道 log tar 4.6 width += arr open ret http://acm.hdu.edu.cn/showproblem.php?pid=6172 題目大意:按照給出的公式算出an 解題思路:an=4an-1+17an-2-12an-3,不要問

2017多校第10場 HDU 6172 Array Challenge 猜公式,矩陣冪

set its typedef == name main d+ space img 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=6172 題意:如題。 解法: #include <bits/stdc++.h&g

HDU - 5858 Hard Problem (simpson積分)

asr \n int show turn push first 陰影部分 bubuko 原題鏈接 題意: 給定一個邊長為n的正方形,求陰影部分面積 思路: 現將圖形順時針旋轉 45° 然後建立坐標系,寫出陰影部分方程,用Simpson積分算一下就行

HDU - 6172:Array Challenge (BM線性遞推)

oid bit pan gin https challenge pre linear res 題意:給出,三個函數,h,b,a,然後T次詢問,每次給出n,求sqrt(an); 思路:不會推,但是感覺a應該是線性的,這個時候我們就可以用BM線性遞推,自己求出前幾項,然後

hdu 4403 A very hard Aoshu problem(dfs)

【題目】 A very hard Aoshu problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/

A hard Aoshu Problem HDU

Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. Nowadays, Aoshu is getting more and more difficul

HDU 1097.A hard puzzle【快速冪或規律】【8月12】

A hard puzzle Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.eve

HDU 1097 A hard puzzle(快速冪)

Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT pro

HDU 6172 Array Challenge (打表找規律+矩陣快速冪 17多校第十場第2題)

題目連結 題意 分析 不得不佩服AC這道題的人腦洞,為什麼你們這麼熟練。。。打表找規律無所不能。 因為我們無法處理開方的取模問題,因此我們不能一步步求。我們令fn=⌊an−−√⌋,則打表

HDU-5858 Hard problem(數學公式、計算幾何)

題意: 已知正方形邊長,圓是內切圓,1/4圓半徑等於正方形邊長,求圖中陰影部分的面積。 思路: 對於我這種高中畢業之後就再沒做過幾何的人還是挺困難的,亂七八糟的公式都忘掉了。 做完輔助線之後,其實就

HDU 6172 Array Challenge【推公式/猜+矩陣快速冪】

題目連結 題意:給一堆公式,求⌊a[n]‾‾‾‾√⌋的值。 官方題解的公式推的實在是沒什麼道理,但是這個xjb亂猜我真的是一口老血噴出來。。。 令f(n)=⌊a[n]‾‾‾‾√⌋,則f(n)=4f

HDU 5858 Hard problem(計算幾何)

Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description cjj is fun with math prob