UVALive5052 Genome Evolution(想法题)
来源:互联网 发布:电脑网络账号密码忘记 编辑:程序博客网 时间:2024/06/06 03:45
题意:
给你两个1~n的排列A和B,统计A,B有多少个子集是相等,序列要求连续的,长度要大于1。
分析:
记录一下B序列的各个整数的位置,然后在从A开始统计,因为他是集合关系的相等,所以要求长度相同,元素相同,接着枚举长度的同时,又因为我们要求的序列是连续的,所以我们找出位置的最大和最小的位置,然后他们的长度如果和我们枚举的长度相等的话,那么这个显然就是正确的了
#include <cstdio>#include <iostream>#include <vector>#include <algorithm>#include <cstring>#include <string>#include <map>#include <cmath>#include <queue>#include <set>using namespace std;typedef long long ll;const int INF = 0x3f3f3f3f;const int N = 3000 + 9;int a[N],b[N],p[N];int main() { //freopen("f.txt","r",stdin); int n,l,r; while(~scanf("%d",&n)&&n){ for(int i=0;i<n;i++)scanf("%d",&a[i]); for(int i=0;i<n;i++)scanf("%d",&b[i]),p[b[i]]=i; int ans=0; for(int i=0;i<n;i++){ int cnt=1; l=r=p[a[i]]; for(int j=i+1;j<n;j++){ if(p[a[j]]>r)r=p[a[j]]; if(p[a[j]]<l)l=p[a[j]]; cnt++; if(r-l+1==cnt)ans++; } } printf("%d\n",ans); } return 0;}/*Sample Input43 2 1 41 2 4 353 2 1 5 43 2 1 5 40Sample Output310*/
0 0
- UVALive5052 Genome Evolution(想法题)
- Genome Evolution uvalive5052
- uva 1481 - Genome Evolution(暴力)
- Genome Evolution LA5052
- UvaLive-5052-Genome Evolution
- UVALive - 5052 Genome Evolution
- UVa 1481 - Genome Evolution
- LA 5052 Genome Evolution -
- LA 5052 Genome Evolution
- UVa 1481 Genome Evolution 解题报告(枚举)
- UVALive - 5052 Genome Evolution 贪心
- Uva LA 5052 Genome Evolution
- LA 5052 Genome Evolution (思维)
- UVaLive LA 5052 UVa 1481 - Genome Evolution (很巧妙的思维)
- UVA 1481 - Genome Evolution(枚举技巧)
- UVA - 1481 Genome Evolution 公式+二分
- UVA 1481 Genome Evolution(高效算法优化)
- (一)理解Visual Genome
- Soot -- Soot中的一些语句细节
- Quartz2D学习笔记
- 常用加密算法
- http请求的8种方式
- Python中安装Tkinter模块
- UVALive5052 Genome Evolution(想法题)
- PHP输入流php://input
- angular分页插件tm.pagination
- Mybatis对Oracle批量插入的配置
- Android中动态加载dex技术初探(插件化技术学习)
- Spring的IOC和AOP
- 190. Reverse Bits*
- 带你读开源—ASP.NET_MVC(十)
- 自定义ContentProvider内容提供者