思路:

原来string类能sort 和 swap....太强了....

注意:字典序最小输出,因为某个地方写挫了,sort了n发,代码挫。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; int tol;
map<string,int>id;
map<int,string>xs;
string ss[20],sss[20]; bool ma[20][20]; int main()
{
string t;
string s;
int n,kk;
id.clear();
xs.clear();
tol=0;
cin>>n>>kk;
for(int i=0; i<n; i++)
cin>>sss[i];
sort(sss,sss+n); for(int i=0;i<n;i++)
{
id[sss[i]]=i;
xs[i]=sss[i];
} memset(ma,false,sizeof(ma));
while(kk--)
{
cin>>s>>t;
ma[id[s]][id[t]]=ma[id[t]][id[s]]=true;
} vector<int> k,res;
int ans=0;
for(int i=0; i<(1<<n); i++)
{
k.clear();
for(int j=0; j<n; j++)
{
if(i&(1<<j))
k.push_back(j);
}
int sz=k.size();
bool flag=true;
for(int p=0; p<sz; p++)
for(int q=0; q<sz; q++)
if(ma[k[p]][k[q]])
flag=false;
if(flag&&ans<sz)
{
res.clear();
ans=sz;
for(int p=0; p<sz; p++)
res.push_back(k[p]);
}
} int num=res.size();
printf("%d\n",num);
for(int i=0; i<num; i++)
ss[i]=xs[res[i]]; sort(ss,ss+num);
for(int i=0; i<num; i++)
cout<<ss[i]<<endl;
return 0;
}

CodeForces 114B 【STL应用】的更多相关文章

  1. Codeforces 997D(STL+排序)

    D. Divide by three, multiply by two time limit per test 1 second memory limit per test 256 megabytes ...

  2. Codeforces 979D (STL set)(不用Trie简单AC)

    题面: 传送门 题目大意: 给定一个空集合,有两种操作: 一种是往集合中插入一个元素x,一种是给三个数x,k,s,问集合中是否存在v,使得gcd(x,v)%k==0,且x+v<=s若存在多个满足 ...

  3. CodeForces 190C STL

    Portal: http://codeforces.com/problemset/problem/190/C 一道卡输入输出的蛋疼题 题意:给你一个由pair和int所组成的沙茶字符串(最大含有1e5 ...

  4. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  6. 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn

    题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边 ...

  7. Codeforces 701C They Are Everywhere(Two pointers+STL)

    [题目链接] http://codeforces.com/problemset/problem/701/C [题目大意] 给出 一个字符串,里面包含一定种类的字符,求出一个最短的子串,使得其包含该字符 ...

  8. Codeforces 799B - T-shirt buying(STL)

    题目链接:http://codeforces.com/problemset/problem/799/B 题目大意:有n件T恤,每件T体恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种 ...

  9. Codeforces Round #595 (Div. 3)D1D2 贪心 STL

    一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...

随机推荐

  1. PHP继承中$this的问题

    在父类中的构造函数中使用$this , 这是$this指的是正在实例化的子类对象,不管是parent还是继承调用父类的构造函数. 如: class CompanyController extends ...

  2. Unity3D之Mesh(五)绘制圆

    前言: Unity3D中Mesh的基本单位是三角形,而圆形就是由许许多多的三角形组成的.那么我们就知道了绘制圆形的Mesh需要两个变量:圆的半径  以及分割数: 一.实现过程 基本过程与之前的类似,最 ...

  3. Java微信开发_Exception_03_非微信官方网页-invalid signature

    由于natapp免费隧道的域名是系统随机分配的,老是在变.故昨天又换了内网映射工具,分别换了ngrok和花生壳,然而在做JSSDK网页开发时,按了微信的view菜单按钮进行页面跳转时,微信官方提示“非 ...

  4. javaScript-基础篇(一)

    1.如何插入JS 使用<script>标签在HTML网页中插入JavaScript代码.注意, <script>标签要成对出现,并把JavaScript代码写在<scri ...

  5. codeforces 776C Molly's Chemicals(连续子序列和为k的次方的个数)

    题目链接 题意:给出一个有n个数的序列,还有一个k,问在这个序列中有多少个子序列使得sum[l, r] = k^0,1,2,3…… 思路:sum[l, r] = k ^ t, 前缀和sum[r] = ...

  6. 使用pjsip传输已经编码的视频,源码在github

    pjsip功能很强,做sip rtp语音通话库首选.在2.0之后,也支持视频.不过,它的视频功能缺省是从视频设备采集,然后进行编译,再发送出去的.假设,我们已经有了视频源,比如IP摄像机,不需要采集和 ...

  7. ACM学习历程—HDU5490 Simple Matrix (数学 && 逆元 && 快速幂) (2015合肥网赛07)

    Problem Description As we know, sequence in the form of an=a1+(n−1)d is called arithmetic progressio ...

  8. django models class 不识别问题解决方案

    目录 1. 事情起因 2. 排查经过 3. 总结 1. 事情起因 今天在写代码的时候,在django 的models目录中新增了一个pkg.py文件,里面定义了一个class, 在执行 makemig ...

  9. BZOJ1033:[ZJOI2008]杀蚂蚁

    我对模拟的理解:https://www.cnblogs.com/AKMer/p/9064018.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...

  10. bzoj 1927 星际竞速 —— 最小费用最大流

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1927 首先注意到这是个DAG: 考虑每个点从哪里来,可以是瞬移来的,也可以是从某个点走过来的 ...