HDU 1551 Cable master【二分答案】】的更多相关文章

题意:给出n块木板,它们分别的高度,现在要把它们裁切成k块,问裁切成的最大的高度 二分答案,上限是这n块木板里面的最大值 然后每一个答案去判断一下是否满足能够裁切成k块 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include&l…
Cable master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1428    Accepted Submission(s): 522 Problem Description Inhabitants of the Wonderland have decided to hold a regional programming con…
题目链接:http://poj.org/problem?id=1064 有n条绳子,长度分别是Li.问你要是从中切出m条长度相同的绳子,问你这m条绳子每条最长是多少. 二分答案,尤其注意精度问题.我觉得关于浮点数的二分for循环比while循环更好一点.注意最后要用到floor 保证最后答案不会四舍五入. #include <iostream> #include <cstdio> #include <cmath> using namespace std; int n ,…
题解:很显然的二分检索,在算法艺术上看过原题,不过这里要注意精度: #include <cstdio> int n,m; ]; bool test(double x){ ,i; ;i<=n;i++)num+=int(a[i]/x); if(num>=m){ return true; }else{ return false; } } int main() { while(scanf("%d%d",&n,&m),n||m){ int i ; ; ;…
Cable master 求电缆的最大长度(二分法)   Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect com…
题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to conn…
Sort Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2377    Accepted Submission(s): 610 Problem Description Recently, Bob has just learnt a naive sorting algorithm: merge sort. Now, Bob receiv…
有n个数字,你需要把这n个数字合成一个数字,每次只能把k个数字合并成一个,花费为这k个数字的和. 给一个最大花费,问不超过这个最大花费的情况下,k的最小值. Sample Input 1 5 25 1 2 3 4 5 Sample Output 3 这个题很容易想到二分答案+优先队列check 然而这样复杂度是 O(n logn*logn ),会TLE(这特么都会TLE?加个读入优化就过了) 可以先给所有数字排个序,然后用两个队列,一个存原来的数字,一个存新合成的数字. 所以两个队列都是有序的.…
题目 这是一个简单的游戏,在一个n*n的矩阵中,找n个数使得这n个数都在不同的行和列里并且要求这n个数中的最大值和最小值的差值最小. Input 输入一个整数T表示T组数据. 对于每组数据第一行输入一个正整数n(1<=n<=100)表示矩阵的大小. 接着输入n行,每行n个数x(0<=x<=100). Output 对于每组数据输出一个数表示最小差值. Sample Input 141 1 1 12 2 2 23 3 3 34 4 4 4 Sample Output 3 分析 首先就…
题目地址:http://poj.org/problem?id=1064 有N条绳子,它们的长度分别为Ai,如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长能有多长. 二分绳子长度,然后验证即可.复杂度o(nlogm) #include<cstdio> #include<iostream> #include<string.h> #include<algorithm> #include<math.h> #include<stdbool.…