ural 2071. Juice Cocktails
2071. Juice Cocktails
Memory limit: 64 MB
Input
Output
Sample
| input | output |
|---|---|
3 |
3 |
Problem Source: Ural Regional School Programming Contest 2015
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
#define INF (1000000001)
#define sz(x) ((int) (x).size())
#define pub push_back const int N = ;
const string STORE[] = {"A", "AB", "B", "BP", "ABP", "AP", "P"};
int n, m;
string data[N];
vector<int> cnt[];
int arr[N], it[N], pos[];
string origin[], tmp[];
int ansPos[]; inline void input()
{
cin >> n;
for(int i = ; i < n; i++) cin >> data[i];
} inline int work()
{
char ch[] = {'A', 'B', 'P'};
int it[] = {}, ret = ;
for(int t = ; t < ; t++)
for(int i = ; i < m; i++)
if(tmp[i][it[i]] == ch[t])
{
it[i]++;
int j = i;
while(j + < m)
{
if(it[j + ] >= sz(tmp[j + ])) break;
if(tmp[j + ][it[j + ]] != ch[t]) break;
j++;
it[j]++;
}
ret++;
i = j;
}
return ret;
} inline int num(string &str)
{
int x;
if(str == "A") x = ;
else if(str == "AB") x = ;
else if(str == "B") x = ;
else if(str == "BP") x = ;
else if(str == "ABP") x = ;
else if(str == "AP") x = ;
else if(str == "P") x = ;
return x;
} inline bool cmp(string a, string b)
{
int x = num(a), y = num(b);
return x < y;
} inline void solve()
{
for(int i = ; i < n; i++)
if(data[i] == "A") cnt[].pub(i);
else if(data[i] == "AB") cnt[].pub(i);
else if(data[i] == "B") cnt[].pub(i);
else if(data[i] == "BP") cnt[].pub(i);
else if(data[i] == "ABP") cnt[].pub(i);
else if(data[i] == "AP") cnt[].pub(i);
else if(data[i] == "P") cnt[].pub(i); m = ;
for(int i = ; i < ; i++)
if(sz(cnt[i]))
{
pos[m] = i;
m++;
}
int ans = INF;
do
{
for(int i = ; i < m; i++) tmp[i] = STORE[pos[i]];
int o = work();
if(ans > o)
{
ans = o;
for(int i = ; i < m; i++) ansPos[i] = pos[i];
}
} while(next_permutation(pos, pos + m)); int out = ;
printf("%d\n", ans);
for(int i = ; i < m; i++)
for(int j = ; j < sz(cnt[ansPos[i]]); j++)
{
out++;
if(out == n) printf("%d\n", cnt[ansPos[i]][j] + );
else printf("%d ", cnt[ansPos[i]][j] + );
}
} int main()
{
ios::sync_with_stdio();
input();
solve();
return ;
}
ural 2071. Juice Cocktails的更多相关文章
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- 【BZOJ-4435】Juice Junctions 最小割树(分治+最小割)+Hash
4435: [Cerc2015]Juice Junctions Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 20 Solved: 11[Submi ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
- ural 2065. Different Sums
2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...
随机推荐
- 项目之solr全文搜索工具的安装
1. Solr简介 Solr是一个基于Lucene的Java搜索引擎服务器.Solr 提供了层面搜索.命中醒目显示并且支持多种输出格式(包括 XML/XSLT 和 JSON 格式).它易于安装和配置, ...
- SOCKet 编程 简介
“一切皆Socket!” 话虽些许夸张,但是事实也是,现在的网络编程几乎都是用的socket. ——有感于实际编程和开源项目研究. 我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览 ...
- XMPP框架下微信项目总结(6)刷新好友列表(删除,添加好友)
原理:1 服务器(openfire)添加/删除 好友,会向客户端(app)发送消息, 2 代理(xmppStreamDelegate)监听到添加/删除消息后,花名册模块(RosterModule)会在 ...
- python 连接sql server
linux 下pymssql模块的安装 所需压缩包:pymssql-2.1.0.tar.bz2freetds-patched.tar.gz 安装: tar -xvf pymssql-2.1.0.tar ...
- 《C#本质论》读书笔记(12)委托和Lambda表达式
12.1.委托概述 12.1.2 委托的数据类型 为了减少重复代码数量,可以将比较方法作为参数传递给 BubbleSort()方法.此外,为了将方法作为参数传递,必须有一个能够标识方法的数据类型--也 ...
- EasyUi – 1.入门
1.页面引用. jquery,easyui,主题easyui.css,图标ico.css,语言zh_CN.js <script src="Scripts/jquery-easyui-1 ...
- 与你相遇好幸运,Waterline的多表关联
>一对一关联 表示一个模型可能只与另一个模型关联.为了使模型知道它与其他哪些模型关联,外键必需包含在记录中.. http://imfly.github.io/sails-docs/concept ...
- OS Boot Loader -- 启动器
这篇文章先抛出来,现在还没有彻底研究明白,但可以做个个人的小结和整理: 记得刚开始搞Linux的时候,普遍采用的是grub,后来有了grub2,尤其是在ubuntu那种非常差劲的不稳定的更新频繁的系统 ...
- sqlplus链接数据库报ORA-09925: Unable to create audit trail file
[localhost.localdomain]:[/oracle11/app/oracle11/product/11.2.0/dbhome_1/dbs]$ sqlplus / as sysdba SQ ...
- [LeetCode] Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...