hdu 5719 Arrange 贪心
Arrange
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
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.
For each test case, the first line of input contains single integer n (1≤n≤105).
The second line contains n integers, the i-th integer denotes Bi (1≤Bi≤n).
The third line contains n integers, the i-th integer denotes Ci (1≤Ci≤n).
3
2 1 1
2 2 3
5
5 4 3 2 1
1 2 3 4 5
0
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.
#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+,M=1e7+,inf=1e9+;
const ll mod=;
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=;
int flag=;
for(i=;i<x;i++)
scanf("%d",&a[i]);
for(i=;i<x;i++)
scanf("%d",&b[i]);
if(a[]!=b[])
ans=;
for(i=;i<x;i++)
{
if(a[i]!=a[i-]&&b[i]!=b[i-])
ans=;
else if(a[i]>a[i-])
ans=;
else if(b[i]<b[i-])
ans=;
else if(a[i]!=a[i-]||b[i]!=b[i-])
flag++;
else
{
ans*=(b[i]-flag-a[i]+);
flag++;
ans%=mod;
}
}
printf("%I64d\n",ans);
}
return ;
}
hdu 5719 Arrange 贪心的更多相关文章
- hdu 5719(Arrange)(冷静分析)
A数组显示从0到i的最小值B数组显示从0到i的最大值由此可得:A数组是单调不增的(怎么也会不使得最小值变大)B数组是单调不减的.设premin和premax为i位以前的最小值和最大值.可以得出以下几点 ...
- HDU 5719 Arrange
根据条件,某些位置的数字就可以确定了.确定过程中如果有冲突,则无解. 如果B中出现了递增,C中出现了递减,则无解. 对于每一个未确定的a[i],ans需要更新,ans=ans*((c[i]-b[i]+ ...
- Hdu 4864(Task 贪心)(Java实现)
Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...
- D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...
- hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...
- hdu 2037简单贪心--活动安排问题
活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...
- HDU 4310 Hero (贪心算法)
A - Hero Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- hdu 4268 multiset+贪心
Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...
随机推荐
- 前端代码tomcat下简单部署
软件 filezilla [ftp] + visionapp Remote Desktop[远程桌面] (前提:前后端代码分离,如前端angular实现) ftp上传到机器{软件 filezill ...
- delphi xe-intarweb 功能记录
IWServerController.HistoryEnabled := True; //使浏览器后退.前进按钮有效TIWForm2.Create(WebApplication).Show; //建 ...
- 18.android studio 安装ing
1.首先得FQ,在谷歌中搜索android studio 2.安装时出现的问题. a. 解决方法,重启电脑,进入Bios,找到并将值设置为 :Intel Virtual Technology=Enab ...
- yum -y install epel-release
EPEL - Fedora Project Wiki https://fedoraproject.org/wiki/EPEL
- flask大全
django:重武器,内部包含了非常多组件:ORM.Form.ModelForm.缓存.Session,中间件,信号等... flask:短小精悍.内部没有太多组件,第三方组件非常丰富 1.初识fla ...
- Maven 整合SSH框架
1. 传递依赖冲突 1.1 传递依赖:A(项目)依赖B,B依赖C(1.1版本),B是A的直接依赖,C是A的传递依赖; A(项目)又依赖D,D依赖C(1.2版本),此时,C有两个版本,产生冲突; 1.2 ...
- JQuery基础与事件和动画
JQuery语法 1.JQuery("选择器").action; 通过选择器调用时间函数 但Jquery可以用$符号代替,即$("选择器").action; ① ...
- Linux入门之运维(1) 系统监控 vmstat top
vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况.这个命令是我查看Linux/Unix最 ...
- Pandas 删除指定列中为NaN的行
定位要删除的行 需求:删除指定列中NaN所在行. 如下图,’open‘ 列中有一行为NaN,定位到它,然后删除. 定位: df[np.isnan(df['open'])].index # 这样即可定位 ...
- OVN实战---《A Primer on OVN》翻译
overview 在本文中,我们将在三个host之间创建一个简单的二层overlay network.首先,我们来简单看一下,整个系统是怎么工作的.OVN基于分布式的control plane,其中各 ...