hdu5719 Arrange
首先,根据题意可得B数组应是单调不升的,C数组是单调不降的。
可以发现A_1 = B_1 = C_1A1=B1=C1,所以如果B_1 \neq C_1B1≠C1无解。
进一步,我们发现如果B_i < B_{i-1}Bi<Bi−1,A_i = B_iAi=Bi;如果C_i > C_{i-1}Ci>Ci−1,A_i = C_iAi=Ci。但是如果B_i < B_{i-1}Bi<Bi−1和C_i > C_{i-1}Ci>Ci−1同时满足,就会产生冲突导致无解。
考虑B_i = B_{i-1}Bi=Bi−1和C_i = C_{i-1}Ci=Ci−1同时满足的情况,此时应有A_i \in (B_i,C_i)Ai∈(Bi,Ci)且A_iAi没有在之前使用过。因为(B_i,C_i)(Bi,Ci)是不断变大的,我们只需维护一下这个区间内有多少值已经被使用过了,用乘法原理统计答案即可。注意到如果某时刻A_iAi没有值可以使用,也会导致无解。
时间复杂度O(Tn)O(Tn)。
Arrange
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 543 Accepted Submission(s): 191
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<stdio.h>
using namespace std;
const int maxx = ;
int b[maxx];
int c[maxx];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
int flag=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&b[i]);
if(i!=){
if(b[i]>b[i-]) flag=;
}
}
long long ans=;
for(int i=;i<n;i++){
scanf("%d",&c[i]);
if(i&&flag){
if(c[i]<c[i-]) flag=;
if(c[i]!=c[i-]&&b[i]!=b[i-]) flag=;
if(c[i]-b[i]<i) flag=;
if(c[i]<=b[i]) flag=;
if(c[i]==c[i-]&&b[i]==b[i-])
ans*=(c[i]-b[i]+-i);
else ans*=;
ans%=;
// cout<<" "<<"i"<<i<<" ans: "<<ans<<endl;
}else{
if(b[i]!=c[i]){
flag=;
}
}
}
if(flag){
printf("%lld\n",ans);
}else{
printf("0\n");
}
}
return ;
}
hdu5719 Arrange的更多相关文章
- hdu-5719 Arrange(组合数学)
题目链接: Arrange Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 通过Measure & Arrange实现UWP瀑布流布局
简介 在以XAML为主的控件布局体系中,有用于完成布局的核心步骤,分别是measure和arrange.继承体系中由UIElement类提供Measure和Arrange方法,并由其子类Framewo ...
- WPF/Silverlight Layout 系统概述——Arrange(转)
Arrange过程概述 普通基类属性对Arrange过程的影响 我们知道Measure过程是在确定DesiredSize的大小,以便Arrange过程参考这个DesiredSize,确定给MyPane ...
- poj 2441 Arrange the Bulls(状态压缩dp)
Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to ...
- 重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree
原文:重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree [源码下载] 重新想象 ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- dplyr 数据操作 数据排序 (arrange)
在R中,我们在整理数据时,经常需要对数据排序,以便数据增强数据的可读性. 下面我们来看下dplyr中的,arrange函数 arrange(.data, ...) 跟filter()类似,arrang ...
- Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...
- numpy的函数使用(一):np.arrange()
arrange函数用于创建等差数组. 返回一个有起点和终点固定长的list e.g.[1, 2, 3],起点是1,终点是5,步长是1.步长相当于等差数列中的公差. 参数:可以接受1.2.3个参数. 注 ...
随机推荐
- InternalError: (pymysql.err.InternalError) (1205, u'Lock wait timeout exceeded; try restarting transaction')
在mysql innodb中使用事务,如果插入或者更新出错,一定要主动显式地执行rollback,否则可能产生不必要的锁而锁住其他的操作 我们在使用数据库的时候,可以使用contextlib,这样异常 ...
- iOS:使用block代码块实现事件处理过程中的回调
block是什么,这里就不多加强调了,它的优点: 第一:执行效率高,速度快 第二:使用起来比代理简单,省却不少代码,增强代码美感 有一些小的知识点要强调一下: 第一点:它类似于一个匿名函数,也跟jav ...
- go语言基础之Printf和Println的区别
1.示例 package main //必须有一个main包 import "fmt" func main() { a := 10 //一段一段处理,自动加换行 fmt.Print ...
- 流畅的python第十三章正确重载运算符
运算符重载基础 不能重载内置类型的运算符 不能新建运算符,只能重载现有的 某些运算符不能重载-------is,and,or和not(不过位运算符&,|和~可以) 一元运算符
- material.setTexture("sampler",tex) assetbundle 下失效
做镜面反射本来写很顺 在手机上测的时候 发现settexture这里绑不上 查好久 是assetbundle的缘故 因为动态加载的 obj用了mat01 我在反射脚本里动态修改mat01而不是拿 re ...
- TensorFlow进阶(一)----张量的阶和数据类型
张量的阶和数据类型 TensorFlow用张量这种数据结构来表示所有的数据.你可以把一个张量想象成一个n维的数组或列表.一个张量有一个静态类型和动态类型的维数.张量可以在图中的节点之间流通.其实张量更 ...
- 模糊搜索:concat各种函数详解、like操作符、通配符
if(StringUtils.isNotBlank(queryBean.getConditions())){ hqlBuilder.addWhereClause(" concat(this. ...
- KMP字符串模式匹配详解(zz)
刚看到位兄弟也贴了份KMP算法说明,但本人觉得说的不是很详细,当初我在看这个算法的时候也看的头晕昏昏的,我贴的这份也是网上找的.且听详细分解: KMP字符串模式匹配详解 来自CSDN A_B_ ...
- centos 5.4中mysql主从同步配置方法
安装环境•centos 5.4•mysql 5.1.xx 采用rpm直接安装•xtrabackup 1.2.22 采用rpm直接安装1. Master:/etc/my.cnf 代码如下 复制代码 [ ...
- (转)PV、UV、IP之间的区别与联系
PV是网站分析的一个术语,用以衡量网站用户访问的网页的数量.对于广告主,PV值可预期它可以带来多少广告收入.一般来说,PV与来访者的数量成正比,但是PV并不直接决定页面的真实来访者数量,如同一个来访者 ...