CodeForces 448D HDU 4907 二分--二分---自己又变渣了--

J - Task schedule
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

有一台机器,并且给你这台机器的工作表,工作表上有n个任务,机器在ti时间执行第i个任务,1秒即可完成1个任务。 
有m个询问,每个询问有一个数字q,表示如果在q时间有一个工作表之外的任务请求,请计算何时这个任务才能被执行。 
机器总是按照工作表执行,当机器空闲时立即执行工作表之外的任务请求。
 

Input

输入的第一行包含一个整数T, 表示一共有T组测试数据。 

对于每组测试数据: 
第一行是两个数字n, m,表示工作表里面有n个任务, 有m个询问; 
第二行是n个不同的数字t1, t2, t3....tn,表示机器在ti时间执行第i个任务。 
接下来m行,每一行有一个数字q,表示在q时间有一个工作表之外的任务请求。 

特别提醒:m个询问之间是无关的。 

[Technical Specification]
1. T <= 50 
2. 1 <= n, m <= 10^5 
3. 1 <= ti <= 2*10^5, 1 <= i <= n 
4. 1 <= q <= 2*10^5 
 

Output

对于每一个询问,请计算并输出该任务何时才能被执行,每个询问输出一行。
 

Sample Input

      
      
1 5 5 1 2 3 5 6 1 2 3 4 5
 

Sample Output

      
      
4 4 4 4 7
 


二分查找区间中时间大于工作的--


代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool fafe[200100];
int ge[200100];
void s()
{
    int a,n,m;
    memset(fafe,false,sizeof(fafe));
    scanf("%d%d",&n,&m);
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a);
        fafe[a]=true;
    }
    ge[0]=0;
    for (int i=1;i<200100;i++)
    {
        ge[i]=ge[i-1];
        if (fafe[i])
            ge[i]++;
    }
    while (m--)
    {
        scanf("%d",&a);
        if (!fafe[a])
        {
            printf("%d\n",a);
            continue;
        }
        int L=a,M,R=200010,ans=0;
        while (L<=R)
        {
            M=(L+R)/2;
            if (ge[M]-ge[a]<M-a)
            {
                R=M-1;
                ans=M;
            }
            else
                L=M+1;
        }
      //  printf("%d   666\n",ans);
        if (ans)
            printf("%d\n",ans);
       // else
         //   printf("")
    }
}
int main()
{
    int t;scanf("%d",&t);
    while (t--)
    {
        s();
    }
    return 0;
}


K - Multiplication Table
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Bizon the Champion isn't just charming, he also is very smart.

While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?

Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.

Input

The single line contains integers nm and k(1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m).

Output

Print the k-th largest number in a n × m multiplication table.

Sample Input

Input
2 2 2
Output
2
Input
2 3 4
Output
3
Input
1 10 5
Output
5

Hint

2 × 3 multiplication table looks like this:

1 2 3
2 4 6


无奈---开始一直想要用二维的查找---然后不知道怎么写--
让求的是乘积中的一个数--1-n*m二分即可---保留最小的个数大于等于k的那个数---


代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL __int64
LL n,m,k;
LL zhao(LL xx)
{
    LL lp=0;
    for (LL i=1;i<=m;i++)
        lp+=min(xx/i,n);
    return lp;
}
int main()
{
    scanf("%I64d%I64d%I64d",&n,&m,&k);
    LL ans=0,L=1,R=k,M;
    if (m>n)
    {
        M=m;m=n;n=M;
    }
    while (L<=R)
    {
        M=(L+R)/2;
        if (zhao(M)>=k)
        {
            ans=M;
            R=M-1;
        }
        else
            L=M+1;
    }
    printf("%I64d\n",ans);
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值