思路:

字符串其实只有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. bg/fg/jobs

    用于将某个任务放置后台运行,一般会与 ctrl+ z , fg, & 符号联用. 典型的场景就是将耗时的任务放于后台运行,例如打包某个占用空间大的目录,

  2. Luogu P1903 BZOJ 2120 数颜色 带修改的莫队

    https://www.luogu.org/problemnew/show/P1903 之前切过这道题,复习莫队再切一遍,不过我之前写的是主席树和树状数组,也不知道我当时怎么想的…… 这个题卡常我没写 ...

  3. python模块之psutil

    一.模块安装 1.简介 psutil是一个跨平台库(http://pythonhosted.org/psutil/)能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息. ...

  4. 金蝶kis 16.0专业版-破解01

    Kingdee.KIS.MobAppSer>MainViewModel 经过反混淆后,找到导入LIcense文件后的验证函数. 下面仅需进行逆向生成即可,为什么一定要进行生成lic文件方式进行破 ...

  5. C Primer Plus--C存储类、链接和内存管理之存储类(storage class)

    目录 存储类 作用域 链接 存储时期 自动变量 寄存器变量 具有代码块作用域的静态变量 具有外部链接的静态变量 extern关键字 具有内部链接的静态变量 多文件 存储类 C为变量提供了5种不同的存储 ...

  6. Alpha(2/6)

    队名:無駄無駄 组长博客 作业博客 组员情况 张越洋 过去两天完成了哪些任务 任务分配.进度监督 提交记录(全组共用) 接下来的计划 沟通前后端成员,监督.提醒他们尽快完成各自的进度 还剩下哪些任务 ...

  7. 安装 sqoop

    简介 Sqoop是一个用来将Hadoop(Hive.HBase)和关系型数据库中的数据相互转移的工具,可以将一个关系型数据库(例如:MySQL ,Oracle ,Postgres等)中的数据导入到Ha ...

  8. mac安装rust

    1.安装 curl https://sh.rustup.rs -sSf | sh 使用brew各种出错,还慢. 2编译 source $HOME/.cargo/env 3.版本查看 rustc --v ...

  9. Eclipse 搭建Struts2

    Eclipse版本 Mars Release (4.5.0) Struts版本 struts-2.5.20 下载地址:https://struts.apache.org/download.cgi#st ...

  10. Windows安装Redis并添加本地自启动服务并解决客户端dll报错

    参考文章:https://blog.csdn.net/realjh/article/details/82026160 Redis下载: https://github.com/MicrosoftArch ...