• hdu 5719 Arrange 贪心


    Arrange

    Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)


    Problem Description
    Accidentally, Cupid, god of desire has hurt himself with his own dart and fallen in love with Psyche. 

    This has drawn the fury of his mother, Venus. The goddess then throws before Psyche a great mass of mixed crops.

    There are n heaps of crops in total, numbered from 1 to n

    Psyche needs to arrange them in a certain order, assume crops on the i-th position is Ai.

    She is given some information about the final order of the crops:

    1. the minimum value of A1,A2,...,Ai is Bi.

    2. the maximum value of A1,A2,...,Ai is Ci.

    She wants to know the number of valid permutations. As this number can be large, output it modulo 998244353.

    Note that if there is no valid permutation, the answer is 0.
     
    Input
    The first line of input contains an integer T (1T15), which denotes the number of testcases.

    For each test case, the first line of input contains single integer n (1n105).

    The second line contains n integers, the i-th integer denotes Bi (1Bin).

    The third line contains n integers, the i-th integer denotes Ci (1Cin).
     
    Output
    For each testcase, print the number of valid permutations modulo 998244353.
     
    Sample Input
    2 3 2 1 1 2 2 3 5 5 4 3 2 1 1 2 3 4 5
     
    Sample Output
    1 0
    Hint
    In the first example, there is only one valid permutation (2,1,3) . In the second example, it is obvious that there is no valid permutation.
    思路:最小值最大值成递减递增函数;前面取的数肯定在之后的区间内,flag一下;
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll __int64
    #define esp 0.00000000001
    const int N=1e5+10,M=1e7+10,inf=1e9+10;
    const ll mod=998244353;
    int a[N];
    int b[N];
    int main()
    {
        int x,y,z,i,t;
        int T;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&x);
            ll ans=1;
            int flag=1;
            for(i=0;i<x;i++)
            scanf("%d",&a[i]);
            for(i=0;i<x;i++)
            scanf("%d",&b[i]);
            if(a[0]!=b[0])
            ans=0;
            for(i=1;i<x;i++)
            {
                if(a[i]!=a[i-1]&&b[i]!=b[i-1])
                ans=0;
                else if(a[i]>a[i-1])
                ans=0;
                else if(b[i]<b[i-1])
                ans=0;
                else if(a[i]!=a[i-1]||b[i]!=b[i-1])
                flag++;
                else
                {
                    ans*=(b[i]-flag-a[i]+1);
                    flag++;
                    ans%=mod;
                }
            }
            printf("%I64d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    python邮件之附件
    python3.5之smtp
    一台Linux上搭建两个tomcat
    mysql 初探(一)
    python监视mysql最大连接数
    P3658 [USACO17FEB]Why Did the Cow Cross the Road III P cdq分治
    P4793 [AHOI2008]矩形藏宝地 cdq分治 线段树
    P2487 [SDOI2011]拦截导弹 线段树 cdq分治
    P3157 [CQOI2011]动态逆序对 cdq分治
    P4169 [Violet]天使玩偶/SJY摆棋子 cdq分治
  • 原文地址:https://www.cnblogs.com/jhz033/p/5679646.html
Copyright © 2020-2023  润新知