CodeForces 114B 【STL应用】
2024-10-19 16:27:01
思路:
原来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;
}
最新文章
- nodejs学习笔记一
- js的类型及调试下的辨识
- 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap
- 数据结构《17》---- 自动补齐之《二》----Ternary Search Tree
- PHP中CURL方法curl_setopt()函数的参数
- UOJ #10 pyx的难题
- Reading Famous blog to prevent me wasting time on blind wandering
- 机器学习实战-边学边读python代码(5)
- PHP验证码
- RESTful架构
- 解决 Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 的问题
- springmvc中url-pattern的大坑
- JavaScript高级程序设计16.pdf
- Ceph BlueStore 解析:Object IO到磁盘的映射
- Windows核心编程&;进程
- 奖品列表组件【仿swiper】
- 前端面试题整理—ajax篇
- 高性价比 VPS virtwire Host
- Linux配置SSH免登录
- Maven的安装与本地仓库的搭建
热门文章
- Javascript 模块化编程 --RequireJs
- python 正则表达式(一)
- jmeter--简单使用
- CodeForces - 1C:Ancient Berland Circus (几何)
- CodeForces - 1019D(BZOJ3707圈地):Large Triangle (几何,找面积为S的三角形)
- ACM学习历程—UESTC 1215 Secrete Master Plan(矩阵旋转)(2015CCPC A)
- NOIp2018集训test-10-18 (bike day4)
- POJ1958:Strange Towers of Hanoi
- asp.net异常处理和错误页配置
- MySQL Sending data导致查询很慢的问题详细分析