CodeForces 114B 【STL应用】
思路:
原来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应用】的更多相关文章
- Codeforces 997D(STL+排序)
D. Divide by three, multiply by two time limit per test 1 second memory limit per test 256 megabytes ...
- Codeforces 979D (STL set)(不用Trie简单AC)
题面: 传送门 题目大意: 给定一个空集合,有两种操作: 一种是往集合中插入一个元素x,一种是给三个数x,k,s,问集合中是否存在v,使得gcd(x,v)%k==0,且x+v<=s若存在多个满足 ...
- CodeForces 190C STL
Portal: http://codeforces.com/problemset/problem/190/C 一道卡输入输出的蛋疼题 题意:给你一个由pair和int所组成的沙茶字符串(最大含有1e5 ...
- 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 ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn
题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边 ...
- Codeforces 701C They Are Everywhere(Two pointers+STL)
[题目链接] http://codeforces.com/problemset/problem/701/C [题目大意] 给出 一个字符串,里面包含一定种类的字符,求出一个最短的子串,使得其包含该字符 ...
- Codeforces 799B - T-shirt buying(STL)
题目链接:http://codeforces.com/problemset/problem/799/B 题目大意:有n件T恤,每件T体恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种 ...
- Codeforces Round #595 (Div. 3)D1D2 贪心 STL
一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...
随机推荐
- jQuery横向手风琴图片滑块
jQuery横向手风琴图片滑块是一款非常不错的jQuery特效横向手风琴图片滑块插件,可以自动播放,也可以鼠标滑过时切换.+ 欢迎喜欢的朋友下载研究 源码下载页:http://www.huiyi8.c ...
- python 链接sharepoint 2013 REST api
import requests,simplejson from requests_ntlm import HttpNtlmAuth p1 = requests.get("http://you ...
- ATL com的dll文件与tlb文件
一..tlb文件: 只有COM组件才有tlb文件,普通dll文件没有. 包含内容: 1.它包含了COM类和接口的GUID值,接口的函数声明信息,并不是接口的实现文件.相当于类和接口的头文件. tlb文 ...
- java jdk1.7后 sting intern()方法与之前的区别
public static void main(String[] args) { String s1 = new StringBuilder("计算机").append(" ...
- Havel-Hakimi定理(握手定理)
Havel-Hakimi定理(握手定理) 由非负整数组成的非增序列s(度序列):d1,d2,…,dn(n>=2,d1>=1)是可图的,当且仅当序列: s1:d2 – 1,d3 – 1,…, ...
- ACM学习历程—Hihocoder 1290 Demo Day(动态规划)
http://hihocoder.com/problemset/problem/1290 这题是这次微软笔试的第三题,过的人比第一题少一点,这题一眼看过去就是动态规划,不过转移方程貌似不是很简单,调试 ...
- [IBM]掌握Ajax,Ajax中的高级请求和响应
掌握 Ajax, Ajax 中的高级请求和响应 http://www.ibm.com/developerworks/cn/xml/wa-ajaxintro1.html http://www.ibm.c ...
- jqgrid--api,官网demo,编辑
api参考: http://blog.csdn.net/hurryjiang/article/details/7551477 官网demo: http://www.trirand.com/blog/j ...
- BZOJ2548:[CTSC2002]灭鼠行动
我对模拟的理解:https://www.cnblogs.com/AKMer/p/9064018.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...
- 多puppetmaster,多ca,keepalived+haproxy(nginx)puppet集群搭建
多puppetmaster,多ca,keepalived+haproxy(nginx)puppet集群搭建 一.服务器详情 192.168.122.111 pm01.jq.com pm01 #(pup ...