2019牛客国庆集训派对day2 B Higher h-index(二分)

mac2022-06-30  27

链接:https://ac.nowcoder.com/acm/contest/1107/B 来源:2019牛客国庆集训派对day2

题目描述 The h-index of an author is the largest h where he has at least h papers with citations not less than h. Bobo has no papers and he is going to publish some subsequently. If he works on a paper for x hours, the paper will get (a⋅x) citations, where a is a known constant. It’s clear that x should be a positive integer. There is also a trick – one can cite his own papers published earlier. Given Bobo has n working hours, find the maximum h-index of him.输入描述 The input consists of several test cases and is terminated by end-of-file. Each test case contains two integers n and a. 1 ≤ n ≤ 109 0 ≤ a ≤ n The number of test cases does not exceed 104.输出描述 For each test case, print an integer which denotes the maximum h-index.输入 3 0 3 1 1000000000 1000000000输出 1 2 1000000000备注 For the first sample, Bobo can work 3 papers for 1 hour each. With the trick mentioned, he will get papers with citations 2, 1, 0. Thus, his h-index is 1. For the second sample, Bobo can work 2 papers for 1 and 2 hours respectively. He will get papers with citations 1 + 1, 2 + 0. Thus, his h-index is 2.

  题意:Bobo 印刷一些纸张,他有 n 个小时,他可以选择任意的时间段( x小时 )去印刷纸张,当前纸张的贡献是 a × x,如果当前的纸张之前有印刷好的纸张,那么当前纸张的贡献还要加上前面印刷好的纸张的数量。问最大的 h,h表示至少有 h 张纸的贡献至少为 h。   思路:我们假设每张纸都有 1 小时的时间来印刷,直接二分 h,mid >= n - mid + a ,一共印刷了 n 张纸,其中满足条件的有 mid 张,n - mid 是前面生产好的纸张加上 a 是这些纸的最小的贡献。前面的式子如果成立说明当前的贡献(n - mid + a)满足题意,并且可以更大,否则说明纸张数量过多,减小即可。

#include<bits/stdc++.h> using namespace std; typedef long long ll; const int Max_n = 1e6 + 10; int a, n; bool check(int mid) { return mid >= n - mid + a; } int main() { while(~scanf("%d%d", &n, &a)) { int l = 1, r = n, ans = 0; while(l <= r) { int mid = (l + r) / 2; if(check(mid)) { ans = n - mid + a; r = mid - 1; } else l = mid + 1; } printf("%d\n", ans); } return 0; } /** * Copyright(c) * All rights reserved. * Author : Max_n * Date : 2019-10-02-13.16.09 * Problem : Higher h-index */
最新回复(0)