思路:

字符串其实只有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. CSS3 新增选择器:伪类选择器和属性选择器

    一.结构(位置)伪类选择器( : ) 1.:first-child 2.:last-child 3.:nth-child(n)或者:nth-child(2n)或者:nth-child(2n+1) &l ...

  2. HTML插入音频和视频:audio和video标签及其属性

    一.上传到第三方网站,然后引入例如视频上传到优酷网,然后得到代码 <iframe height=498 width=510 src='http://player.youku.com/embed/ ...

  3. ES安装手册

    http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.htmlhttps://githu ...

  4. Note_4.9

    2019/4/9 奇奇怪怪的笔记 关于代码,基本上是现写的,可能连编译都过不了 因为是简单算法场,所以就很不走心了昂,/小纠结 图论相关  最小生成树 prim,kruskal 最小生成树的切割性质 ...

  5. 【洛谷】P4167 [Violet]樱花

    题面 又懒得弄题面,开个传送门吧 分析 人生第一次切数学题,我们先把方程写出来 $$\frac {1}{x}+\frac {1}{y}=\frac {1}{n!}$$ 现在我们知道的条件是x,y都是正 ...

  6. elasticsearch_dsl.exceptions.ValidationException: You cannot write to a wildcard index.

    elasticsearch_dsl.exceptions.ValidationException: You cannot write to a wildcard index. 这里是因为版本不匹配的问 ...

  7. [spring-boot] 多环境配置

    application-{profile}.properties 按照格式创建两个配置文件,一个DEV环境,一个测试环境 修改其端口: server.port=8888 DEV server.port ...

  8. useContext 让父子组件传值更简单(五)

    有了useState和useEffect已经可以实现大部分的业务逻辑了,但是React Hooks中还是有很多好用的Hooks函数的,比如useContext和useReducer. 在用类声明组件时 ...

  9. useEffect代替常用生命周期函数(三)

    在用Class制作组件时,经常会用生命周期函数,来处理一些额外的事情(副作用:和函数业务主逻辑关联不大,特定时间或事件中执行的动作,比如Ajax请求后端数据,添加登录监听和取消登录,手动修改DOM等等 ...

  10. 如何选题?| 什么样的科学问题 | 研究项目才是有意义的?| scientific method

    搞科研,尤其是生命科学,经常会觉得自己做的东西是坨屎,没有任何意义. 在硕博的时候这种感觉会非常强烈,一个是自己思考能力不足:二是你的项目不是你设计的,不懂个中缘由,只执行的话就会很无聊,找不到意义感 ...