HDU 5432 BC - Pyramid Split(二分 + 模拟)
2015-09-12 21:41
543 查看
新生如何加入ACM集训队? |
Pyramid SplitTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 56 Accepted Submission(s): 29 Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which have square undersides,let's call them pyramids. Anyone of them can be defined by the square's length and the height,called them width and height. To easily understand,all the units are mile.Now Ming has n pyramids,there height and width are known,Xiao Ming wants to make them again to get two objects with the same volume. Of course he won't simply melt his pyramids and distribute to two parts.He has a sword named "Tu Long" which can cut anything easily. Now he put all pyramids on the ground (the usdersides close the ground)and cut a plane which is parallel with the water level by his sword ,call this plane cutting plane. Our mission is to find a cutting plane that makes the sum of volume above the plane same as the below,and this plane is average cutting plane.Figure out the height of average cutting plane. Input First line: T, the number of testcases.(1≤T≤100) Then T testcases follow.In each testcase print three lines : The first line contains one integers n(1≤n≤10000), the number of operations. The second line contains n integers A1,…,An(1≤i≤n,1≤Ai≤1000) represent the height of the ith pyramid. The third line contains n integers B1,…,Bn(1≤i≤n,1≤Bi≤100) represent the width of the ith pyramid. Output For each testcase print a integer - **the height of average cutting plane**. (the results take the integer part,like 15.8 you should output 15) Sample Input 2 2 6 5 10 7 8 702 983 144 268 732 166 247 569 20 37 51 61 39 5 79 99 Sample Output 1 98这道题目可以直接二分也可以模拟通过,这里的是二分代码#include <map> #include <set> #include <cmath> #include <ctime> #include <queue> #include <vector> #include <cctype> #include <cstdio> #include <string> #include <cstring> #include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define pb push_back #define mp make_pair #define fillchar(a, x) memset(a, x, sizeof(a)) #define copy(a, b) memcpy(a, b, sizeof(a)) typedef long long LL; typedef pair<int, int > PII; typedef unsigned long long uLL; template<typename T> void print(T* p, T* q, string Gap = " ") { int d = p < q ? 1 : -1; while(p != q) { cout << *p; p += d; if(p != q) cout << Gap; } cout << endl; } template<typename T> void print(const T &a, string bes = "") { int len = bes.length(); if(len >= 2)cout << bes[0] << a << bes[1] << endl; else cout << a << endl; } const int INF = 0x3f3f3f3f; const int MAXM = 1e5; const int MAXN = 1e4 + 5; const double eps = 1e-4; int T, n, A[MAXN], B[MAXN],MAXH; bool C(double m) { double Mm = 0, M = 0; for(int i = 0; i < n; i ++) { if(m > A[i]) { M += B[i] * B[i] * A[i] * 1.0 / 3.0; } else { double Bi = (A[i] - m) * 1.0 / A[i]; M += B[i] * B[i] * A[i] * 1.0 / 3.0; Mm += B[i] * Bi * B[i] * Bi * (A[i] - m) / 3.0; } } if(M >= 2.0 * Mm) return true; return false; } int main() { cin >> T; while(T --) { cin >> n; MAXH = 0; for(int i = 0; i < n; i ++) { cin >> A[i]; MAXH = max(MAXH, A[i]); } for(int i = 0; i < n; i ++) { cin >> B[i]; } double lb = 0, ub = MAXH; while(ub - lb > eps) { double mid = (ub + lb) / 2.0; if(C(mid)) ub = mid; else lb = mid; } printf("%d\n", (int)ub); } return 0; } |
相关文章推荐
- i++ i-- 问题小记
- 2015-09-09 [一点资讯]--数据抓取和处理工程师--5面
- 1.Objective-C基础学习
- Jq将页面值传至模态框的用法
- 网络性能测试工具iperf详细使用图文教程
- php添加mysql扩展
- 11.tftp和nfs服务器
- 窗口-CCF测试往届题
- 如何在Android模拟器上安装apk文件
- Hadoop/spark安装实战(系列篇3) Hadoop 伪分布模式安装
- 一个简单的jsp+servlet实例,实现简单的登录
- java练习:打印 数字1、2、3、4的组合,不能以4开头,1和3不能相邻,且数字不能重复
- shell script
- [vb.net]最简单的邮件发送
- php环境的搭建
- 样式表单位
- php添加socket的扩展
- 数据结构之---C语言实现连式多项式
- Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial
- sg函数