博客
关于我
CodeForces - 1330B Dreamoon Likes Permutations
阅读量:331 次
发布时间:2019-03-04

本文共 1749 字,大约阅读时间需要 5 分钟。

CodeForces - 1330B Dreamoon Likes Permutations

在这里插入图片描述
注意点:当输出的答案前半段与后半段相等时,只算一个(卡死我个菜鸡了)

ac代码:

#include
#include
#include
using namespace std;const int maxn=2e5+7;int a[maxn]={ };bool b[maxn]={ };int mx,n,l1,l2;bool jg1(){ memset(b,0,sizeof b); for(int i=1;i<=l1;i++) { b[a[i]]=1; } for(int i=1;i<=l1;i++) { if(b[i]==0) return 0; } memset(b,0,sizeof b); for(int i=l1+1;i<=n;i++) { b[a[i]]=1; } for(int i=1;i<=l2;i++) { if(b[i]==0) return 0; } return 1;}bool jg2(){ memset(b,0,sizeof b); for(int i=1;i<=l2;i++) { b[a[i]]=1; } for(int i=1;i<=l2;i++) { if(b[i]==0) return 0; } memset(b,0,sizeof b); for(int i=l2+1;i<=n;i++) { b[a[i]]=1; } for(int i=1;i<=l1;i++) { if(b[i]==0) return 0; } return 1;}int main(){ ios::sync_with_stdio(false); int t; cin>>t; while(t--) { cin>>n; memset(a,0,sizeof a); mx=0; for(int i=1;i<=n;i++) { cin>>a[i]; mx=max(mx,a[i]); } l1=mx,l2=n-mx; bool f1=jg1(),f2=jg2(); if(l1<=0||l2<=0) { cout<<"0\n"; } else if(f1&&f2) { if(mx*2!=n) { cout<<"2\n"; cout<
<<" "<
<<"\n"; cout<
<<" "<
<<"\n"; } else { cout<<"1\n"; cout<
<<" "<
<<"\n"; } } else if(f1&&f2==0) { cout<<"1\n"; cout<
<<" "<
<<"\n";// cout<
<<" "<
<<"\n"; } else if(f1==0&&f2) { cout<<"1\n";// cout<
<<" "<
<<"\n"; cout<
<<" "<
<<"\n"; } else { cout<<"0\n"; } }}

转载地址:http://evrq.baihongyu.com/

你可能感兴趣的文章
MySQL之DML
查看>>
Mysql之IN 和 Exists 用法
查看>>
MYSQL之REPLACE INTO和INSERT … ON DUPLICATE KEY UPDATE用法
查看>>
MySQL之SQL语句优化步骤
查看>>
MYSQL之union和order by分析([Err] 1221 - Incorrect usage of UNION and ORDER BY)
查看>>
Mysql之主从复制
查看>>
MySQL之函数
查看>>
mysql之分组查询GROUP BY,HAVING
查看>>
mysql之分页查询
查看>>
Mysql之备份与恢复
查看>>
mysql之子查询
查看>>
MySQL之字符串函数
查看>>
mysql之常见函数
查看>>
Mysql之性能优化--索引的使用
查看>>
mysql之旅【第一篇】
查看>>
Mysql之索引选择及优化
查看>>
mysql之联合查询UNION
查看>>
mysql之连接查询,多表连接
查看>>
mysql乐观锁总结和实践 - 青葱岁月 - ITeye博客
查看>>
mysql也能注册到eureka_SpringCloud如何向Eureka中进行注册微服务-百度经验
查看>>