• Codefroces 760 B. Frodo and pillows


    B. Frodo and pillows
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.

    Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?

    Input

    The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 109, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.

    Output

    Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.

    Examples
    Input
    4 6 2
    Output
    2
    Input
    3 10 3
    Output
    4
    Input
    3 6 1
    Output
    3
    Note

    In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.

    In the second example Frodo can take at most four pillows, giving three pillows to each of the others.

    In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.

    #include <iostream> 
    #include <algorithm> 
    #include <cstring> 
    #include <cstdio>
    #include <vector> 
    #include <queue> 
    #include <cstdlib> 
    #include <iomanip>
    #include <cmath> 
    #include <ctime> 
    #include <map> 
    #include <set> 
    using namespace std; 
    #define lowbit(x) (x&(-x)) 
    #define max(x,y) (x>y?x:y) 
    #define min(x,y) (x<y?x:y) 
    #define MAX 100000000000000000 
    #define MOD 1000000007
    #define pi acos(-1.0) 
    #define ei exp(1) 
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 0x3f3f3f3f3f 
    #define mem(a) (memset(a,0,sizeof(a))) 
    typedef long long ll;
    int main()
    {
        ll count,n,m,k,ans,pos,cnt,inf;
        while(scanf("%I64d%I64d%I64d",&n,&m,&k)!=EOF)
        {
            cnt=0;count=1;inf=0;
            m-=n;ans=1;
            pos=max(k-1,n-k);
            for(ll i=1;i<=pos;i++)
            {
                cnt+=(i*2-1);//交替铺最多消耗枕头数
            }
            if(m>cnt)//平铺
            {
                inf=(m-cnt)/n;
                m-=(inf*n);
            }
            while(m>0)//交替铺
            {
                if(k-count>=1) ans++;
                if(k+count<=n) ans++;
                m-=ans;
                count++;
            }
            printf("%I64d
    ",inf+count);
        }
        return 0;
    }
  • 相关阅读:
    《解密腾讯海量服务之道》讲座笔记
    图解 Paxos 一致性协议
    向量时钟算法简介——本质类似MVCC
    logback配置
    Protocol Buffers简明教程
    分布式调用技术 RPC VS REST
    Dubbo和Spring Cloud微服务架构对比
    Spring Boot学习笔记
    relatedTarget、fromElement、toElement相关元素
    12个不可不知的Sublime Text应用技巧和诀窍
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7263933.html
Copyright © 2020-2023  润新知