Hoj 2995 Area

来源:互联网 发布:思科软件下载 编辑:程序博客网 时间:2024/06/05 21:17

题目:http://acm.hit.edu.cn/hoj/problem/view?id=2995

本题主要是理解题意和理解二分法的思路。

具体还需要学会求简单的定积分。

关于x ≥ 1, y ≥ 1, x * y ≤ C。


 代码:

#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <algorithm>#include <stack>#include <queue>#include <map>using namespace std;//计算x ≥ 1, y ≥ 1, x * y ≤ c时S内有多少个整数点int count(int c){    int ans = 0;    for(int i=1;i<=c;i++)    {        ans += c/i;    }    return ans;}//二分法求lower_boundint calc(int n){    int low = 1;    int high = n;    int pos = 1;    while(low < high)    {        int mid = (low + high)/2;        if(count(mid)<n)        {            low = mid + 1;            pos = low;        }        else        {            high = mid;            pos = mid;        }    }    return pos;}int main(){#ifndef ONLINE_JUDGE    freopen("in.txt","r",stdin);#endif    int t;    int n;    int c;    scanf(" %d",&t);    for(int i=0;i<t;i++)    {        scanf(" %d",&n);        if(n == 0)        {            printf("0.0000\n");            continue;        }        c = calc(n);        printf("%.4lf\n",c*log(c) - (c - 1));    }    return 0;}


原创粉丝点击