CF1277D Let's Play the Words?
思路:
字符串其实只有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?的更多相关文章
随机推荐
- webuploader+asp.net如何实现分片+断点续传
文件夹数据库处理逻辑 public class DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject() ...
- CF1185F Two Pizzas 状压
你发现 pizza 种类数不会很多,状压一下就可以了 code: #include <bits/stdc++.h> #define M 11 #define N 100005 #defin ...
- C++问题--error LNK2019: 无法解析的外部符号 __imp__wsprintfW
一.问题 当编译运行C++连接Redis时,出现错误Win32_Interop_d.lib(Win32_ANSI.obj) : error LNK2019: 无法解析的外部符号 __imp__wspr ...
- golang-复习1
结构体: 是一种数据类型 type Person struct{ //l类型定义,地位等价与 int byte boo string ……通常放在全局位置 name string sex byte ...
- 高效率编辑器 Vim——操作篇,非常适合 Vim 新手
原文地址:https://linuxtoy.org/archives/efficient-editing-with-vim.html vim教程:http://vimcasts.org/ https: ...
- Educational Codeforces Round 64(ECR64)
Educational Codeforces Round 64 CodeForces 1156A 题意:1代表圆,2代表正三角形,3代表正方形.给一个只含1,2,3的数列a,ai+1内接在ai内,求总 ...
- Spring boot Aop 示例
需要的依赖 <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-aop -- ...
- 回声消除(AEC)原理
一.前言 因为工作的关系,笔者从2004年开始接触回声消除(Echo Cancellation)技术,而后一直在某大型通讯企业从事与回声消除技术相关的工作,对回声消除这个看似神秘.高端和难以理解的技术 ...
- 前端通用下载文件方法(兼容IE)
之前在网上看到一个博主写的前端通用的下载文件的方法,个人觉得很实用,所以mark一下,方便以后查阅 源文地址(源文还有上传/下载excel文件方法) 因为项目要求要兼容IE浏览器,所以完善了一下之前博 ...
- vim卡死
使用vim时,如果你不小心按了 Ctrl + s后,你会发现不能输入任何东西了,像死掉了一般,其实vim并没有死掉,这时vim只是停止向终端输出而已,要想退出这种状态,只需按Ctrl + q 即可恢复 ...