zoukankan      html  css  js  c++  java
  • 【雅礼联考DAY01】逃跑

    #pragma GCC optimize(2)
    #pragma GCC optimize(3)
    #include<cstdio>
    using namespace std;
    
    const int N = 30000;
    const double INF = 1e8;
    int n , l , a[N + 5] , b[N + 5] , c[N + 5] , q[N + 5] , head , tail , Mk , Mc;
    double ans , f[N + 5] , w[N + 5];
    struct tree{double max , tag;}t[(N << 2) + 5];
    
    inline double max(double x , double y) {return x > y ? x : y;}
    
    inline void build(int l , int r , int k)
    {
    	t[k] = (tree){0 , 0};
    	if (l == r) 
    	{
    		t[k].max = f[l];
    		return;
    	}
    	int mid = (l + r) >> 1;
    	if (l <= mid) build(l , mid , k << 1);
    	if (r > mid) build(mid + 1 , r , k << 1 | 1);
    	t[k].max = max(t[k << 1].max , t[k << 1 | 1].max);
    }
    
    inline void pushdown(int k)
    {
    	if (!t[k].tag) return;
    	t[k << 1].max += t[k].tag;
    	t[k << 1 | 1].max += t[k].tag;
    	t[k << 1].tag += t[k].tag;
    	t[k << 1 | 1].tag += t[k].tag;
    	t[k].tag = 0;
    }
    
    inline void update(int l , int r , int k , int x , double v)
    {
    	if (l == r && l == x)
    	{
    		t[k].max = v;
    		return;
    	}
    	int mid = (l + r) >> 1;
    	pushdown(k);
    	if (x <= mid) update(l , mid , k << 1 , x , v);
    	if (x > mid) update(mid + 1 , r , k << 1 | 1 , x , v);
    	t[k].max = max(t[k << 1].max , t[k << 1 | 1].max);
    }
    
    inline void change(int l , int r , int k , int tl , int tr , double v)
    {
    	if (l >= tl && r <= tr)
    	{
    		t[k].tag += v;
    		t[k].max += v;
    		return;
    	}
    	int mid = (l + r) >> 1;
    	pushdown(k);
    	if (tl <= mid) change(l , mid , k << 1 , tl , tr , v);
    	if (tr > mid) change(mid + 1 , r , k << 1 | 1 , tl , tr , v);
    	t[k].max = max(t[k << 1].max , t[k << 1 | 1].max);
    }
    
    inline double query(int l , int r , int k , int tl , int tr)
    {
    	if (l >= tl && r <= tr) return t[k].max;
    	int mid = (l + r) >> 1;
    	double res = -INF;
    	pushdown(k);
    	if (tl <= mid) res = max(res , query(l , mid , k << 1 , tl , tr));
    	if (tr > mid) res = max(res , query(mid + 1 , r , k << 1 | 1 , tl , tr));
    	return res;
    }
    
    inline bool check(double m)
    {
    	for(register int i = 1; i <= n; i++) w[i] = a[i] - b[i] * m , f[i] = -INF;
    	f[0] = 0;
    	build(0 , n , 1);
    	q[head = tail = 1] = 0;
    	for(register int i = 1; i <= n; i++)
    	{
    		while (head < tail && c[i] >= c[q[tail]])
    		{
    			change(0 , n , 1 , q[tail - 1] , q[tail] - 1 , -w[q[tail]]);
    			tail--;
    		}
    		q[++tail] = i;	
    		change(0 , n , 1 , q[tail - 1] , q[tail] - 1 , w[q[tail]]);
    		f[i] = query(0 , n , 1 , i - l > 0 ? i - l : 0 , i - 1);
    		update(0 , n , 1 , i , f[i]);
    	}
    	return f[n] >= 0;
    }
    
    int main()
    {
    //	freopen("逃跑.in" , "r" , stdin);
    	scanf("%d%d" , &n , &l);
    	for(register int i = 1; i <= n; i++) scanf("%d%d%d" , &a[i] , &b[i] , &c[i]);
    	c[0] = INF;
    	double l = 0 , r = 1e6 , mid;
    	for(register int i = 1; i <= 60; i++)
    	{
    		mid = (l + r) * 0.5;
    		if (check(mid)) l = mid , ans = mid;
    		else r = mid;
    	}
    	
    	if (ans == 0) 
    	{
    		puts("0.000000000e+000");	
    		return 0;
    	}
    	Mk = 0 , Mc;
    	if (ans < 1)
    	{	
    		while (ans < 1) ans *= 10 , Mk++;
    		printf("%.9lfe-" , ans);
    		if (Mk == 0) Mc = 3;
    		else if (Mk < 10) Mc = 2;
    		else if (Mk < 100) Mc = 1;
    		else Mc = 0;
    		while (Mc--) putchar('0');
    		if (Mk > 0) printf("%d" , Mk);
    		return 0;
    	} 
    	while (ans >= 10) ans /= 10 , Mk++;
    	printf("%.9lfe+" , ans);
    	if (Mk == 0) Mc = 3;
    	else if (Mk < 10) Mc = 2;
    	else if (Mk < 100) Mc = 1;
    	else Mc = 0;
    	while (Mc--) putchar('0');
    	if (Mk > 0) printf("%d" , Mk);
    }
    
  • 相关阅读:
    hdu2860 并查集模拟
    hdu 3938 Portal离线并查集
    hdu 2489 Minimal Ratio Tree (DFS枚举+MST)
    hdu 3172 并查集+map
    hdu 1829 A Bug's Life 并查集系列
    hdu 1598 find the most comfortable road
    HDU1198
    【Oracle】【17】表创建后,对表进行操作(添加字段,删除主键约束等)
    【JS】【19】使用Jquery判断是电脑或手机或微信浏览器访问
    【JS】【18】当前时间加减一天和格式化时间格式
  • 原文地址:https://www.cnblogs.com/leiyuanze/p/12337054.html
Copyright © 2011-2022 走看看