zoukankan      html  css  js  c++  java
  • Codeforces Round #299 (Div. 1) A. Tavas and Karafs 水题

    Tavas and Karafs

    Time Limit: 1 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/536/problem/A

    Description

    Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.

    Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.

    For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.

    Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.

    Input

    The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).

    Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.


    1000000000.

    Output

    For each query, print its answer in a single line.

    Sample Input

    2 1 4
    1 5 3
    3 3 10
    7 10 2
    6 4 8

    Sample Output

    4
    -1
    8
    -1

    HINT


    题意

    给你一个等差数列,然后10e6次询问
    问你一次可以吃m个,最多吃t次,问你最多往右吃多少个

    题解:

    傻逼题,只要每个数都小于等于t,前缀和小于等于t*m就好了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    //const int inf=0x7fffffff;   //无限大
    const int inf=0x3f3f3f3f;
    /*
    
    int buf[10];
    inline void write(int i) {
      int p = 0;if(i == 0) p++;
      else while(i) {buf[p++] = i % 10;i /= 10;}
      for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
      printf("
    ");
    }
    */
    //**************************************************************************************
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    ll A,B,q,t,m,l;
    ll ans(ll x)
    {
        return A+(x-1)*B;   
    }
    ll sum(ll l,ll r)
    {
        ll x1=A+(l-1)*B,x2=A+(r-1)*B;
        return 1ll*(x1+x2)*(r-l+1)/2;
    }
    int main()
    {
        scanf("%d%d%d",&A,&B,&q);
        while(q--)
        {
            int l,t,m;
            scanf("%d%d%d",&l,&t,&m);
            int lef=l,rig=inf,mid;
            while(lef<=rig)
            {
                mid=lef+rig>>1;
                if(ans(mid)<=t && sum(l,mid)<=1ll*t*m)lef=mid+1;
                else rig=mid-1;
            }
            if(rig==l-1)printf("-1
    ");
            else printf("%d
    ",rig);
        }
        return 0;
    }
  • 相关阅读:
    CF219D
    HDU 4259 Double Dealing 数学题
    HDU1599 find the mincost route 最小环
    HDU3592 World Exhibition 排队判断3种情况
    POJ3694 Network 加边查询剩余桥的个数
    Flex 如何获得Tree 拖动节点的起始位置
    wcf webconfig配置
    学JS面向对象 以及里面的继承
    sqlserver 几种查询耗时
    ubuntu更改文件夹属性
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4427466.html
Copyright © 2011-2022 走看看