思路:

字符串其实只有0...0, 0...1, 1...0, 1...1四种。

实现:

 #include <bits/stdc++.h>
using namespace std;
set<string> st[];
bool work(set<string>& a, set<string>& b, map<string, int>& mp, vector<int>& res)
{
int d = a.size() - b.size();
for (auto it: a)
{
if (res.size() == d / ) break;
string tmp = it;
reverse(tmp.begin(), tmp.end());
if (b.count(tmp)) continue;
res.push_back(mp[it]);
}
return res.size() >= d / ;
}
int main()
{
int t; cin >> t;
while (t--)
{
for (int i = ; i < ; i++) st[i].clear();
int n; cin >> n;
map<string, int> mp;
for (int i = ; i < n; i++)
{
string s; cin >> s;
mp[s] = i + ;
int a = *s.begin() - '', b = *(s.end() - ) - '';
int p = a * + b;
st[p].insert(s);
}
if (!st[].empty() && !st[].empty() && st[].empty() && st[].empty())
{
cout << - << endl; continue;
}
vector<int> res;
bool ok = false;
if (st[].size() > st[].size()) ok = work(st[], st[], mp, res);
else ok = work(st[], st[], mp, res);
if (ok)
{
cout << res.size() << endl;
for (auto it: res) cout << it << " ";
cout << endl;
}
else cout << - << endl;
}
return ;
}

CF1277D Let's Play the Words?的更多相关文章

随机推荐

  1. Poj 1743 Musical Theme(后缀数组+二分答案)

    Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 28435 Accepted: 9604 Descri ...

  2. pcl-设置多线段宽度和颜色

    显示点云有使用vtk的,有使用 ros 中riz ?库的,使用pcl显示点云数据比较方便,但是对于一些模型形状只能固定特定的效果,比如说直线段,只能绘制点到点两点之间的线段.但是项目需要绘制点1到点2 ...

  3. 各种DTO类最好有 无参数的构造方法

    以一下这个类为例 @Getter @Setter @ToString class Person { private String s; public Person(String s) { this.s ...

  4. os 模块常用方法

    os.remove()删除文件 os.rename()重命名文件 os.walk()生成目录树下的所有文件名 os.chdir()改变目录 os.mkdir/makedirs创建目录/多层目录 os. ...

  5. Spring MVC国际化配置

    Spring MVC国际化配置 前言 项目开发中要考虑支持国际化,框架选用的是Spring MVC框架,那么问题来了Spring MVC如何配置并实现国际化. 实现过程(Maven项目) 对于Spri ...

  6. java非空判断

    是否为 null 是否为 "" 是否为空字符串(引号中间有空格)  如: "     ". 制表符.换行符.换页符和回车 一. 字符串 1. if(str == ...

  7. 【caffe Layer】代码中文注释

    src/caffe/proto/caffe.proto 中LayerParameter部分 // NOTE // Update the next available ID when you add a ...

  8. 根据字符串从资源中取出对应的资源ResourceManager.GetObject

    ResourceManager.GetObject 根据名称从资源中取出资源 需要:我有25张 五笔图片名称是a b c d ...y 这样组成的 每张图片名字只有一个名字 我想通过字符串a取出a这张 ...

  9. 第08组 Alpha冲刺(1/6)

    队名:955 组长博客:https://www.cnblogs.com/cclong/p/11841141.html 作业博客:https://edu.cnblogs.com/campus/fzu/S ...

  10. html5表单重写

    html5表单重写 一.总结 一句话总结: 表单重写用于在提交按钮上指定表单提交的各种信息,比如action <input type="submit" value=" ...