Codeforces 202B Brand New Easy Problem(模拟)
来源:互联网 发布:中华田园犬 知乎 编辑:程序博客网 时间:2024/05/29 18:32
题意:
让你在m个序列中看是否存在给定序列的一个排列,并且计算逆序对数最大值。在找的时候我已开始想通过状压来枚举所有的排列,但是发现效率太慢了,于是听了队友的建议,对于给定序列的每一个排列,对所有的搜索串中进行搜索,这样就快多了。
代码:
//// Created by CQU_CST_WuErli// Copyright (c) 2015 CQU_CST_WuErli. All rights reserved.//// #include<bits/stdc++.h>#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cctype>#include <cmath>#include <string>#include <vector>#include <list>#include <map>#include <queue>#include <stack>#include <set>#include <algorithm>#include <sstream>#define CLR(x) memset(x,0,sizeof(x))#define OFF(x) memset(x,-1,sizeof(x))#define MEM(x,a) memset((x),(a),sizeof(x))#define For_UVa if (kase!=1) cout << endl#define BUG cout << "I am here" << endl#define lookln(x) cout << #x << "=" << x << endl#define SI(a) scanf("%d",&a)#define SII(a,b) scanf("%d%d",&a,&b)#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)#define rep(flag,start,end) for(int flag=start;flag<=end;flag++)#define Rep(flag,start,end) for(int flag=start;flag>=end;flag--)#define Lson l,mid,rt<<1#define Rson mid+1,r,rt<<1|1#define Root 1,n,1#define BigInteger bigntemplate <typename T> T gcd(const T& a,const T& b) {return b==0?a:gcd(b,a%b);}const int MAX_L=2005;// For BigIntegerconst int INF_INT=0x3f3f3f3f;const long long INF_LL=0x7fffffff;const int MOD=1e9+7;const double eps=1e-9;const double pi=acos(-1);typedef long long ll;using namespace std;int n;int m;vector<int> pro;vector<int> arc[11];map<string,int> mp;int idx;void init() { pro.clear(); for (int i=0;i<11;i++) arc[i].clear(); mp.clear(); idx=1;}int get(string& s) { if (!mp.count(s)) mp[s]=idx++; return mp[s];}void print() { for (int i=0;i<pro.size();i++) cout << pro[i] << ' '; cout << endl; for (int i=1;i<=m;i++) { for (int j=0;j<arc[i].size();j++) cout << arc[i][j] << ' '; cout << endl; }}int cal() { map<int,int> mpx; int ret=0; for (int i=0;i<n;i++) { mpx[pro[i]]++; for (int j=pro[i]+1;j<=n;j++) ret+=mpx[j]; } return (n*(n-1)/2)-ret+1;}bool check(int x) { int cnt=0; for (int i=0;i<arc[x].size();i++) { if (arc[x][i]==pro[cnt]) { cnt++; } if (cnt==n) break; } return cnt==n;}int main(){#ifdef LOCAL freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin);// freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout);#endif while (SI(n)==1) { init(); for (int i=1;i<=n;i++) { string x; cin >> x; pro.push_back(get(x)); } SI(m); for (int i=1;i<=m;i++) { int x;SI(x); for (int j=1;j<=x;j++) { string tmp; cin >> tmp; arc[i].push_back(get(tmp)); } }// print(); int ans=0,id=-1; do { int tmp=cal(); int ok=0; int i; for (i=1;i<=m;i++) if (check(i)) { ok=1; break; } if (ok) {// cout << "i=" << i << ' ' << "tmp=" << tmp << endl; if (ans<tmp){ ans=tmp; id=i; } if (ans==tmp && id>i) id=i; } }while (next_permutation(pro.begin(),pro.end())); if (id==-1) cout << "Brand new problem!" << endl; else { cout << id << endl; cout << "[:"; for (int i=1;i<=ans;i++) cout << '|'; cout << ":]\n"; } } return 0;}
0 0
- Codeforces 202B Brand New Easy Problem(模拟)
- CodeForces 202B Brand New Easy Problem
- codeforces 202B Brand New Easy Problem
- cf B. Brand New Easy Problem
- codeforces 278B New Problem
- codeforces 278B New Problem 字符串查找
- Codeforces--629B--Far Relative’s Problem(模拟)
- Codeforces 379B New Year Present(模拟)
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- 【CodeForces】96B - Lucky Numbers (easy)(模拟,字典序全排列)
- [easy]CodeForces-897B Chtholly's request 模拟/找规律
- HDU 2418 Another Easy Problem(模拟)
- 【模拟】Another Easy Problem
- B - An easy problem
- B - An easy problem
- B - An easy problem
- Codeforces Round #170 (Div. 2) B. New Problem
- Codeforces Round #150 (Div. 1) A. The Brand New Function
- [Java视频笔记]day08
- Swift-捕获值
- 【NYOJ】[243]字母统计
- 做事情就要做精
- Swift-闭包是引用类型
- Codeforces 202B Brand New Easy Problem(模拟)
- Swift-非逃逸闭包
- UDP打洞源码及原理分析
- C++复习8
- iOS数据类型转换。
- 《如何制定年计划》观后感
- eclipse导入mysql jdbc驱动包的具体步骤及注意事项
- Java——eclipse中格式化代码快捷键Ctrl+Shift+F失效的解决办法
- POJ 2236 Wireless Network