zoukankan      html  css  js  c++  java
  • Tavas and Karafs 二分+结论

    二分比较容易想到

    #include<map>
    #include<set>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstdio>
    #include<cassert>
    #include<iomanip>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define C 0.5772156649
    #define pi acos(-1.0)
    #define ll long long
    #define mod 1000000007
    #define ls l,m,rt<<1
    #define rs m+1,r,rt<<1|1
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    
    using namespace std;
    
    const double g=10.0,eps=1e-7;
    const int N=2000000+10,maxn=1000000+10,inf=0x3f3f3f;
    
    ll a,b;
    bool ok(ll l,ll r,ll t,ll m)
    {
        if(a+(r-1)*b<=t)
        {
            ll p=a*(r-l+1)+(l+r-2)*(r-l+1)/2*b;
    
            return p<=t*m;
        }
        return 0;
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll n;
        cin>>a>>b>>n;
        while(n--)
        {
            ll l,t,m;
            cin>>l>>t>>m;
            ll L=l,R=10*N;
            while(L<R-1)
            {
                ll mid=(L+R)/2;
              //  cout<<L<<" "<<mid<<" "<<R<<endl;
                if(ok(l,mid,t,m))L=mid;
                else R=mid;
            }
            if(a+(L-1)*b<=t)cout<<L<<endl;
            else cout<<-1<<endl;
        }
        return 0;
    }
    /********************
    2 3 1
    148990 913922 18257
    ********************/
    View Code

    ,而结论就是对于一个递增的数列,每次把m个数减小1,一共减小t次,当最大的那个数小于t,而且数列总和小于t*m时,那么可以取完,否则就不行

  • 相关阅读:
    (六)目标文件目录探测
    (五)物理路径探测
    (四)目标后台的探测
    小妙招
    MFC的一些常用操作
    UNICODE,GBK,UTF-8区别
    c++编程的字符集及其转换
    windows消息的循环机制
    c++ mfc和win32项目
    c++ 一些注意事项
  • 原文地址:https://www.cnblogs.com/acjiumeng/p/7355953.html
Copyright © 2011-2022 走看看