Bestcoder#5 1002
Bestcoder#5 1002
Poor MitsuiTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 336 Accepted Submission(s): 70
Problem Description
Because of the mess Mitsui have made, (not too long ago, Mitsui, leading a group of bully guys, intended to make some trouble and damage to the basketball team.) he was punished to mop the floor this week. And he needs to get some water first.
He takes N broken buckets to get some water. When he turns on the water-tap, the water begins to fill in at a speed V unit water per second.(And this speed will always be V.) As the buckets is broken, when there is water in the bucket, water begins to flow away at a certain speed. Each bucket has its own speed. At a time, there can only be one bucket to receive water from the water-tap, but at the same time water still flows away from the buckets (those contains water at that moment).
We don’t allow a bucket to receive water from the water-tap for more than once or receive water from other buckets. And we assume that Mitsui can change the position of the buckets in a very short time (we can ignore the time it takes) and the capacity of each backet is so large that it can’t be fulfilled.
Now Mitsui wonders can there be a moment that each bucket is filled with a specific volunm of water. If it’s possible, find the earliest one, otherwise he will just go home in a bad mood.
Input
This problem contains multiple tests.
The first line contains a number T (1 ≤ T ≤ 150), which tells the total number of test cases.
Each test consists of three lines, the first line contains two integers, N and V. (1 ≤ N ≤ 40, 1 ≤ V ≤ 40). N tells the number of buckets and V tells the speed of water come out of the water-tap. In the second line, there are N integers, Ai (1 ≤ Ai ≤ 40) is the speed of water flow away from the i-th bucket. In the third line, there are N interges, Bi (0 ≤ Bi ≤ 40) is the volunm of water that Mitsui wants the i-th bucket to contain at that special moment.
Output
This problem is intended to use special judge. But so far, BestCoder doesn’t support special judge. So if it’s possible for Mitsui to optimize his movement to make that happen, you should output a number which tells the earliest time that might happen since Mitsui turns on the water-tap, rounded it into an integer, otherwise just output -1 instead.
Sample Input
23 31 1 32 2 23 31 1 12 2 2
Sample Output
-15
Hint
In the first example, Mitsui can’t make that happen no matter how he arranges the order of the buckets to receive water from the water-tap. So the answer is -1.In the second example, Mitsui can make that happen in 4.75 seconds. And that is the optimal answer. So you should output 5. Please note, If the accurate answer is X, you are recommended to use printf(“%.0f\n”, X) to output the answer in C++.
#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<cmath> #include<map> #include<algorithm> #define M(a,b) memset(a,b,sizeof(a)) using namespace std; int T; int N; double V; double time[]; struct bow { double A,B; bool operator < (const bow& rhs) const { return B/A>rhs.B/rhs.A; } }bo[]; int main() { scanf("%d",&T); while(T--) { scanf("%d%lf",&N,&V); for(int i = ;i<N;i++) { scanf("%lf",&bo[i].A); } for(int i = ;i<N;i++) { scanf("%lf",&bo[i].B); } sort(bo,bo+N); double res = ; int flag = ; for(int i = N-;i>=;i--) { if(bo[i].B==) continue; //不明白为什么需要加上这一句,没理由啊,求hack bo[i].B += bo[i].A*res; if((bo[i].A>=V&&bo[i].B!=)||bo[i].B/(V-bo[i].A)<) {flag = ; break;} res+= bo[i].B/(V-bo[i].A); //cout<<res<<endl; } if(!flag) {puts("-1"); continue;} printf("%.0lf\n",res); } return ; }
Bestcoder#5 1002的更多相关文章
- bestcoder#23 1002 Sequence II 树状数组+DP
Sequence II Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDOJ 4884 & BestCoder#2 1002
TIANKENG’s rice shop Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
- 矩阵快速幂---BestCoder Round#8 1002
当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n) f(n-1)] = [f(n ...
- BestCoder #47 1001&&1002
[比赛链接]cid=608">clikc here~~ ps:真是wuyu~~做了两小时.A出两道题,最后由于没加longlong所有被别人hack掉!,最后竟然不知道hack别人不成 ...
- BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- 简单几何(水)BestCoder Round #50 (div.2) 1002 Run
题目传送门 /* 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 */ /***** ...
- Manacher BestCoder Round #49 ($) 1002 Three Palindromes
题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...
随机推荐
- 结对项目:代码复审+PSP
一.代码复审 首先我从代码风格规范和程序修改两方面进行审查. (一)代码风格规范修改 1 . 代码的部分未缩进:在用markdown粘贴代码时,需要后期tab,无形中加大工作量. 2 . ...
- AC日记——最小的N个和 codevs 1245
1245 最小的N个和 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 有两个长度为 N ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
- C#使用zxing,zbar,thoughtworkQRcode解析二维码,附源代码
最近做项目需要解析二维码图片,找了一大圈,发现没有人去整理下开源的几个库案例,花了点时间 做了zxing,zbar和thoughtworkqrcode解析二维码案例,希望大家有帮助. zxing是谷歌 ...
- 腾讯 auth_token
auth_token 从cookies里取出supertoken=2881515311; function auth_token(str) { var hash = 0; for (var i = 0 ...
- 多线程之任务: Task 基础, 多任务并行执行, 并行运算(Parallel)
Task - 基于线程池的任务(在 System.Threading.Tasks 命名空间下) 多 Task 的并行执行 Parallel - 并行计算(在 System.Threading.Task ...
- css 使图片水平垂直居中
1.利用display:table-cell,具体代码如下: html代码如下: <div class="img_wrap"> <img src="wg ...
- 精灵方向移动问题[math.floor]
local xd = math.cos(math.rad(self._direction));--self._direction方向角度 local yd = math.sin(math.rad(se ...
- Android测试基础题(三)
今天接着给大家带来的是Android测试基础题(三). 需求:定义一个排序的方法,根据用户传入的double类型数组进行排序,并返回排序后的数组 俗话说的好:温故而知新,可以为师矣 packag ...
- UVA1585
#include<stdio.h> #include<string.h> int main(){ int n; ]; scanf("%d",&n); ...