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≤10^5).
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).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=998244353;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e5+10;
const int maxn=1e3+10;
const double eps=1e-6; int b[N],c[N]; int main()
{
int t;
read(t);
while(t--)
{
int n;
read(n);
For(i,1,n)read(b[i]);
For(i,1,n)read(c[i]);
LL ans=1;
int cnt=0;
For(i,1,n)
{
if(i==1)
{
if(b[i]!=c[i]){ans=0;break;}
else cnt++;
continue;
}
if(c[i]<i||b[i]>n-i+1){ans=0;break;}
if(b[i]>b[i-1]||c[i]<c[i-1]||b[i]>c[i]){ans=0;break;}
if(b[i]<b[i-1]&&c[i]==c[i-1])cnt++;
else if(c[i]>c[i-1]&&b[i]==b[i-1])cnt++;
else if(c[i]==c[i-1]&&b[i]==b[i-1])
{
int len=c[i]-b[i]+1-cnt;
cnt++;
ans=ans*(LL)len%mod;
}
else {ans=0;break;}
}
cout<<ans<<"\n";
}
return 0;
}
hdu-5719 Arrange(组合数学)的更多相关文章
- hdu 5719 Arrange 贪心
Arrange Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Proble ...
- 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 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...
- HDU 4497 数论+组合数学
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...
- BestCoder 2nd Anniversary/HDU 5719 姿势
Arrange Accepts: 221 Submissions: 1401 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/2 ...
- poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...
- HDU 4609 3-idiots (组合数学 + FFT)
题意:给定 n 条边,问随机选出 3 条边,能组成三角形的概率是多少. 析:答案很明显就是 能组成三角形的种数 / (C(n, 3)).现在的问题是怎么求能组成三角形的种数. 这个博客说的非常清楚了 ...
- A - Dogs and Cages HDU - 6243(组合数学)
题意:在1—n的数字,放入编号为1—n的框中,每个框只放一个数字,问数字与所放的框的编号不同的个数的期望值. 思路:在1—n中任选一个数字,设为k 那么 k 排到非k编号的框中的方案数为 n!-(n- ...
随机推荐
- 转载自CSDN,结论:windows下按ENTER键应该是\r\n ascii码为 13 10
记得在Windows下学X86汇编语言时,用0DH(\r)和0AH(\n)来输出回车(跳到下一行的开始处).问题来了,在Windows下是 先回车再换行呢还是先换行再回车呢?在Unix系统下换行只有\ ...
- Laravel5.1的控制器分组
Laravel5.1的控制器分组 默认的控制器时直接在app\Http\Controllers下,创建分组名字,路由配置使用:分组名\控制器名@方法名.
- 利用systemtap定位ifconfig dropped数据包的原因
http://blog.chinaunix.net/uid-20662820-id-3842431.html 欢迎转载,转载请保留文章的完整性!Author: Tony <tingw.liu ...
- kibana dev tools快捷键
kibana dev tools快捷键 ctrl+enter 提交请求 ctrl+i 自动缩进 ctrl+enter 提交请求 down 打开自动补全菜单 enter或tab 选中项自动补全 esc ...
- [CSS3] Identify Interactive HTML Elements with CSS Link Pseudo Classes
The interactive pseudo-classes for links (and buttons) allow us to make sure the user knows what ele ...
- C#如何实现挂机锁
首先在主窗体中设置一个子窗体的实例,然后当点击挂机之后,隐藏当前窗体,同时显示子窗体. 把子窗体的背景窗体设置如下属性(主要是背景随便改成一个图片,然后FormBorderStyle改成None, ...
- SolidEdge 如何绘制零件图的剖视图
1 点击检视-剖面,然后选择剖切面 2 比如要全剖,则绘制好方框之后点返回,选择方向. 选择剖切深度,然后预览即可 一个零件可以进行多次剖切
- Java基础 笔记(四)
泛型: 泛型:通过<数据额类型>来接受一种引用数据类型.作用在编译时.使用检查 加入集合的对象是否属于该类型,从而把执行时的问题转换为编译时异常.提高程序的安全性 避免抛出 ClassCa ...
- ubuntu 的权限和目录
/ : 根目录 /bin 和 /sbin中放置的是可执行文件 /etc 里面放的是配置文件 /boot 引导 /mnt 是挂载目录 /home 主目录 /dev 设备 /usr li ...
- 漫谈程序猿系列:无BUG不生活
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm9ydW9r/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...