思路:

原来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. js 判断滚动条的滚动方向

    以下代码实现判断页面的滚动条的滚动方向: var sign = 80;//定义默认的向上滚与向下滚的边界 window.onscroll = window.onresize = function(){ ...

  2. bootstrap中使用日历控件

    在bootstrap中使用日历控件可以参照以下资料: http://www.bootcss.com/p/bootstrap-datetimepicker/index.htm 以下是参照此资料自己做的一 ...

  3. 常见SQL函数需要注意的细节

    版权声明:本文为博主原创文章,未经博主允许不得转载. 这是一位牛人让我们思考的问题,说实话当时真蒙了,函数虽然明白,但细化到这种程度,真的是叫不准啊,下面是几道比较典型的问题,和本人做的实验,不一定准 ...

  4. 机器学习(二十四)— 偏差Bias 与方差Variance

    1.首先 Error = Bias + Variance  Error反映的是整个模型的准确度, Bias反映的是模型在样本上的输出与真实值之间的误差,即模型本身的精准度, Variance反映的是模 ...

  5. linux下安装rpm格式的mysql

    1.下载安装包官网下载.rpm格式安装包,需要下面两个文件: MySQL-server-5.0.26-0.i386.rpm MySQL-client-5.0.26-0.i386.rpm 注:官网下载时 ...

  6. Convolutional Neural Networks for Visual Recognition 4

    Modeling one neuron 下面我们开始介绍神经网络,我们先从最简单的一个神经元的情况开始,一个简单的神经元包括输入,激励函数以及输出.如下图所示: 一个神经元类似一个线性分类器,如果激励 ...

  7. BZOJ3812 清华集训2014 主旋律

    直接求出强联通生成子图的数量较难,不妨用所有生成子图的数量减去非强联通的. 非强联通生成子图在所点后满足编号最小的点所在的强联通分量不是全集. 由于$n$很小,我们可以考虑状态压缩. 对于点集$S$, ...

  8. 1038 Recover the Smallest Number (30)(30 分)

    Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...

  9. pytorch--cpu与gpu load时相互转化

    pytorch------cpu与gpu load时相互转化 torch.load(map_location=)学习 将gpu改为cpu时,遇到一个报错:RuntimeError: Attemptin ...

  10. Android HttpGet和HttpPost设置超时

    HttpPost: private Runnable runnable = new Runnable() { @Override public void run() { String url = Ba ...