• MUTC8 J-The More The Better


    The More The Better

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2568    Accepted Submission(s): 668


    Problem Description
    Given an sequence of numbers {X1, X2, ... , Xn}, where Xk = (A * k + B) % mod. Your task is to find the maximum sub sequence {Y1, Y2, ... , Ym} where every pair of (Yi, Yj) satisfies Yi + Yj <= L (1 ≤ i < j ≤ m), and every Yi <= L (1 ≤ i ≤ m ).
    Now given n, L, A, B and mod, your task is to figure out the maximum m described above.
     

    Input
    Multiple test cases, process to the end of input. Every test case has a single line. A line of 5 integers: n, L, A, B and mod. (1 ≤ n ≤ 2*107, 1 ≤ L ≤ 2*109, 1 ≤ A, B, mod ≤ 109)
     

    Output
    For each case, output m in one line.
     

    Sample Input
    1 8 2 3 6 5 8 2 3 6
     

    Sample Output
    1 4
     

    Source
     

    Recommend
    zhuyuanchen520

    ------------
    简单题,首先想到所有小于 L/2 的,统统可以放进来,最后,按照题意,还可能可以放一个大于 L/2 的数进来,当小于 L/2 的数里面的最大值加上这个大于 L/2 的数的和小于 L 时,答案加一。最后要注意所有数都小于 L/2 的处理。O(n) 算法可过此题。
    ------------
    /** head-file **/
    
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <iomanip>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <list>
    #include <set>
    #include <map>
    #include <algorithm>
    
    /** define-for **/
    
    #define REP(i, n) for (int i=0;i<int(n);++i)
    #define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
    #define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)
    #define REP_1(i, n) for (int i=1;i<=int(n);++i)
    #define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)
    #define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)
    #define REP_N(i, n) for (i=0;i<int(n);++i)
    #define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)
    #define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)
    #define REP_1_N(i, n) for (i=1;i<=int(n);++i)
    #define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)
    #define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)
    
    /** define-useful **/
    
    #define clr(x,a) memset(x,a,sizeof(x))
    #define sz(x) int(x.size())
    #define see(x) cerr<<#x<<" "<<x<<endl
    #define se(x) cerr<<" "<<x
    #define pb push_back
    #define mp make_pair
    
    /** test **/
    
    #define Display(A, n, m) {                      
        REP(i, n){                                  
            REP(j, m) cout << A[i][j] << " ";       
            cout << endl;                           
        }                                           
    }
    
    #define Display_1(A, n, m) {                    
        REP_1(i, n){                                
            REP_1(j, m) cout << A[i][j] << " ";     
            cout << endl;                           
        }                                           
    }
    
    using namespace std;
    
    /** typedef **/
    
    typedef long long LL;
    
    /** Add - On **/
    
    const int direct4[4][2]={ {0,1},{1,0},{0,-1},{-1,0} };
    const int direct8[8][2]={ {0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1} };
    const int direct3[6][3]={ {1,0,0},{0,1,0},{0,0,1},{-1,0,0},{0,-1,0},{0,0,-1} };
    
    const int MOD = 1000000007;
    const int INF = 0x3f3f3f3f;
    const long long INFF = 1LL << 60;
    const double EPS = 1e-9;
    const double OO = 1e15;
    const double PI = acos(-1.0); //M_PI;
    
    const int maxn=11111111;
    LL ai;
    LL n,L,A,B,mod;
    LL mx,mi;
    LL ans;
    int main()
    {
        while (cin>>n>>L>>A>>B>>mod)
        {
            mx=0;
            mi=L;
            ans=0;
            ai=B;
            REP_1(i,n)
            {
                ai+=A;
                while (ai>=mod) ai-=mod;
                if (ai<=L/2)
                {
                    ans++;
                    mx=max(mx,ai);
                }
                else
                {
                    mi=min(mi,ai);
                }
            }
            if (mi+mx<=L) ans++;
            cout<<ans<<endl;
        }
        return 0;
    }
    






     

  • 相关阅读:
    js反爬:请开启JavaScript并刷新该页
    VIEWSTATE等参数处理
    VM+CentOS+Hadoop+Spark集群搭建
    从入门到自闭之Python入门
    从入门到自闭之Python软件命名规范
    从入门到自闭之Python序列化
    从入门到自闭之Python名称空间
    从入门到自闭之Python函数初识
    从入门到自闭之Python随机模块
    从入门到自闭之Python时间模块
  • 原文地址:https://www.cnblogs.com/cyendra/p/3226271.html
Copyright © 2020-2023  润新知