hdu 5719 Arrange

 1 /*******************************************************
 2 题目:    Arrange(hdu 5719)
 3 链接:    http://acm.hdu.edu.cn/showproblem.php?pid=5719
 4 解法:    可以发现 A1=B1=C1,如果B1不等于C1无解。
 5           如果Bi<Bi-1,那么Ai=Bi;如果Ci>Ci-1,那
 6           么Ai=Ci;如果Bi=Bi-1 && Ci=Ci-1那么 Bi<=Ai<=Ci,
 7           并且Ai前面没使用过。其它情款无解。
 8
 9 ********************************************************/
10 #include<iostream>
11 #include<cstdio>
12 #include<algorithm>
13 #include<iostream>
14 #include<vector>
15 #include<queue>
16 #include<cstring>
17 using namespace std;
18
19 const int mx=100005;
20 long long b[mx],c[mx];
21
22
23 int main()
24 {
25     int t;
26     scanf("%d",&t);
27     while (t--)
28     {
29         int n;
30         scanf("%d",&n);
31         for (int i=1;i<=n;i++) scanf("%I64d",&b[i]);
32         for (int i=1;i<=n;i++) scanf("%I64d",&c[i]);
33         if (b[1]!=c[1])
34         {
35             printf("0\n");
36             continue;
37         }
38         long long ans=1;
39         for (int i=2;i<=n;i++)
40         {
41             if ((b[i]<b[i-1]&&c[i]==c[i-1])||(c[i]>c[i-1]&&b[i]==b[i-1]))
42             continue;
43             if (b[i]==b[i-1]&&c[i]==c[i-1])
44             {
45                 if (c[i]-b[i]+1<i)
46                 {
47                     ans=0;
48                     break;
49                 }
50                 ans=(ans*(c[i]-b[i]+2-i))%998244353;
51                 continue;
52             }
53             ans=0;
54             break;
55         }
56         printf("%I64d\n",ans);
57     }
58
59 }
时间: 2024-08-23 09:50:05

hdu 5719 Arrange的相关文章

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 mot

hdu 5719(Arrange)(冷静分析)

A数组显示从0到i的最小值B数组显示从0到i的最大值由此可得:A数组是单调不增的(怎么也会不使得最小值变大)B数组是单调不减的.设premin和premax为i位以前的最小值和最大值.可以得出以下几点:1.第一位,A数组和B数组定然相同,否则无解2.当A[i]>B[i] 无解3.当A[i]<premin,更新最小值,同时意味着这意味只能放A[i],当B[i]>premax,同样操作,当如果两者同时发生,说明有冲突,无解4.当A[i]==premin&&B[i]==prem

hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少?如果不存在,输出0: 思路: 有解的几种条件: 1. mn , mx 变化单调: 2. mn,mx 不能同时变化: 3. 一个位置可选的个数>0; 当解存在时,递推出每次可选择的个数,num += mx[i] - mx[i-1] + mn[i-1] - mn[i] - 1; 即可: 坑:开始想成了

HDU 5719 BestCoder 2nd Anniversary Arrange (DP)

Arrange Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 558    Accepted Submission(s): 198 Problem Description Accidentally, Cupid, god of desire has hurt himself with his own dart and fallen

7.18

题目链接:HDU 5719 Arrange 昨天的B题,昨天做的时候没注意所有谷堆是全排列,看了Clarification才知道,可是不会做. 实际上只需要将自己的代码改动一步就可以了count = count*(c[i]-b[i]-i+2)%mod,也即c[i]-b[i]+1-(i-1) 看这个样例就知道了 4 2 1 1 1 2 2 5 5 #include <iostream> #include <cstdio> #include <algorithm> #inc

HDU 4749 Parade Show(暴力水果)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 Problem Description 2013 is the 60 anniversary of Nanjing University of Science and Technology, and today happens to be the anniversary date. On this happy festival, school authority hopes that the

hdu 5093 Battle ships 最大二分匹配

Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 589    Accepted Submission(s): 233 Problem Description Dear contestant, now you are an excellent navy commander, who is responsible

HDU 1988 &amp; ZOJ 2991 Flipping Burned Pancakes(数学啊+模拟)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1988 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1990 Problem Description The cook at the Frobbozz Magic Pancake House sometimes falls asleep on the job while cooking pancakes. As

hdu 5024 Wang Xifeng&#39;s Little Plot (dfs+暴力)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 194    Accepted Submission(s): 131 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)