zoukankan      html  css  js  c++  java
  • hdu 5719 Arrange

    Arrange

    Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 674    Accepted Submission(s): 236


    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.
     
    Source
     
    #include <iostream>
    #include <queue> 
    #include <stack> 
    #include <map> 
    #include <set> 
    #include <bitset> 
    #include <cstdio> 
    #include <algorithm> 
    #include <cstring> 
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    #define ll long long
    const int mod = 998244353;
    const int maxn = 1e5 + 10;
    int a[maxn], b[maxn];
    int vis[maxn];
    int main() {
        int t;
        scanf("%d", &t);
        while(t--) {
            memset(vis, 0, sizeof(vis));
            int n;
            scanf("%d", &n);
            for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
            for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
            ll ans = 1;
            int flag = 1;
            for(int i = 2; i <= n; i++) {
                if(a[i] != a[i-1] && b[i] != b[i-1]) {
                    flag = 0;
                    break;
                }
                if(a[i] > a[i-1] || b[i] < b[i-1]) {
                    flag = 0;
                    break;
                }
                if(a[i] == a[i-1] && b[i] == b[i-1]) {
                    ans = ans * (b[i] - a[i] - i + 2) % mod;
                }
            }
            if(flag)
                printf("%lld
    ", ans);
            else puts("0");
        }
    }
  • 相关阅读:
    npm安装elasticsearch-reindex
    Linux14_文本编辑器与终端配置
    Linux13_群组的管理和文件权限的管理
    Linux12_用户和权限
    Linux11_文件及目录以及其相关的组织命令
    Linux10_常用命令和操作
    Linux9_安装Linux系统
    基础概念——什么是POSIX
    C++Review21_宏和常量
    C++Review20_C++函数高级特性(重载、内联、const和virtual)
  • 原文地址:https://www.cnblogs.com/lonewanderer/p/5682586.html
Copyright © 2011-2022 走看看