【二分】Urozero Autumn Training Camp 2016 Day 5: NWERC-2016 Problem C. Careful Ascent

二分Vx即可。

#include<cstdio>
#include<algorithm>
using namespace std;
#define EPS 0.00000000001
struct RANGE{
	int l,r;
	double f;
}rs[110];
bool cmp(const RANGE &a,const RANGE &b){
	return a.l<b.l;
}
int xe,ye,n,Left;
bool check(double vx){
	double sumx=0;
	for(int i=1;i<=n;++i){
		sumx+=(double)(rs[i].r-rs[i].l)*vx*rs[i].f;
	}
	return sumx+(double)Left*vx-(double)xe > -EPS;
}
int main(){
//	freopen("c.in","r",stdin);
	scanf("%d%d%d",&xe,&ye,&n);
	Left=ye;
	for(int i=1;i<=n;++i){
		scanf("%d%d%lf",&rs[i].l,&rs[i].r,&rs[i].f);
		Left-=(rs[i].r-rs[i].l);
	}
	sort(rs+1,rs+n+1,cmp);
	double l=-10000000,r=10000000;
	while(r-l>EPS){
		double mid=(l+r)/2.0;
		if(check(mid)){
			r=mid;
		}
		else{
			l=mid+EPS;
		}
	}
	printf("%.11f\n",l);
	return 0;
}
时间: 2024-12-08 19:45:39

【二分】Urozero Autumn Training Camp 2016 Day 5: NWERC-2016 Problem C. Careful Ascent的相关文章

【强连通分量缩点】【DFS】【动态规划】Urozero Autumn Training Camp 2016 Day 5: NWERC-2016 Problem B. British Menu

有向图,不经过重复点的最长链,强连通分量大小不超过5. 每个强连通分量内部暴力预处理任意两对点之间的最长路,外面DAG上dp. 不是很好写,但是预处理完了之后,可以重构每个强连通分量内部的结构,然后整个就变成一张DAG了,就很方便了. #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <

【计算几何】【预处理】【枚举】Urozero Autumn Training Camp 2016 Day 5: NWERC-2016 Problem K. Kiwi Trees

发现由于角的度数和边的长度有限制,那俩圆如果放得下的话,必然是塞在两个角里. 于是预处理n个圆心的位置(注意要判断那个圆会不会和其他的边界相交),然后n^2枚举俩角即可. #include<cstdio> #include<cmath> using namespace std; #define EPS 0.00000001 struct Point{ double x,y; double length(){ return sqrt(x*x+y*y); } }a[2010]; typ

【枚举】【SPFA】Urozero Autumn Training Camp 2016 Day 5: NWERC-2016 Problem I. Iron and Coal

那个人派出的队伍的行走的路径一定前半程是重合的,后半程分叉开来. 于是预处理每个点离1号点的最短路,到最近的铁的最短路,到最近的煤的最短路.(三次BFS / SPFA)然后枚举分岔点,尝试更新答案即可. #include<cstdio> #include<queue> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; queue<int>

2016-2017 ACM-ICPC Northwestern European Regional Programming Contest (NWERC 2016) 个人题解

Problem C Careful Ascent 可怜的我们被卡在了签到题上,当时用的二分来做,结果速度的左右区间写成了[0,1e32],而改成[-1e32,1e32]就通过了,哎-,怎么就没想到去改一下区间的范围呢. 下面是正常的数学解法,类似于解一元一次方程. #include <iostream> using namespace std; typedef long long ll; ll x,y,n; ll a,b;double c; int main(){ cin>>x&g

湖南省第十三届大学生计算机程序设计竞赛 Football Training Camp 贪心

2007: Football Training Camp[原创-转载请说明] Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 228     Solved: 30 Description 在一次足球联合训练中一共有n支队伍相互进行了若干场比赛. 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为平局则两支队伍各得1分. Input 输入包含不超过1000组数据. 每组数据的第

2015 UESTC Winter Training #7【2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest】

2015 UESTC Winter Training #7 2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest 据说这套题写出3题就是金牌水平了... Problem D. Group Stage 足球比赛,现在有n(2<= n <=100)支球队.要从中选拔m(1<= m <=n-1)支球队,每支球队互相比赛一场,即比赛n*(n-1)/2场,胜者得3分,平局各得1分.最后从大到小列出排名,如果有

Petrozavodsk Summer Training Camp 2017

Petrozavodsk Summer Training Camp 2017 Problem A. Connectivity 题目描述:有\(n\)个点,现不断地加边.每条边有一种颜色,如果一个点对\((a, b)\),满足\(a=b\)或对于每一种颜色的子图(图中只有该种颜色的边),\(a, b\)总是连通,则该点对称为好连通.求出每加一条边,好连通的点对数. solution 每个子图用并查集维护连通块,并且用\(vector\)记录每个连通块的点,便于之后进行答案的统计,合并时启发式合并即

D. Marcin and Training Camp

题目链接:http://codeforces.com/contest/1230/problem/D D. Marcin and Training Camp time limit per test: 3 seconds memory limit per test: 256 megabytes input: standard input output: standard output 题目大意: 要组建一个小组,要求小组中每个人都不比所有人强,当一个人懂得一个算法但是另一个不懂那么前者认为他比后者强

D. Marcin and Training Camp ( Codeforces Round #588 (Div. 2) )

Marcin is a coach in his university. There are nn students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. Let's focus on the students. They are indexed with int