博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ 2702 Unrhymable Rhymes 贪心
阅读量:6528 次
发布时间:2019-06-24

本文共 2771 字,大约阅读时间需要 9 分钟。

贪心。能凑成一组就算一组

Unrhymable Rhymes

Time Limit: 10 Seconds      
Memory Limit: 32768 KB      
Special Judge

An amateur poet Willy is going to write his first abstract poem. Since abstract art does not give much care to the meaning of the poem, Willy is planning to impress listeners with unusual combinations of words. He prepared n lines of the future poem, but suddenly noticed that not all of them rhyme well.

Though abstractionist, Willy strongly respects canons of classic poetry. He is going to write the poem that would consist of quatrains. Each quatrain consists of two pairs of rhymed lines. Therefore there can be four types of quatrains, if we denote rhymed lines with the same letter, these types are “AABB”, “ABAB”, “ABBA” and “AAAA”.

Willy divided the lines he composed into groups, such that in each group any line rhymes with any other one. He assigned a unique integer number to each group and wrote the number of the group it belongs next to each line. Now he wants to drop some lines from the poem, so that it consisted of correctly rhymed quatrains. Of course, he does not want to change the order of the lines.

Help Willy to create the longest poem from his material.

Input

There are mutilple cases in the input file.

The first line of each case contains n --- the number of lines Willy has composed (1 <= n <= 4000 ). It is followed by n integer numbers denoting the rhyme groups that lines of the poem belong to. All numbers are positive and do not exceed 109 .

There is an empty line after each case.

Output

On the first line of the output file print k --- the maximal number of quatrains Willy can make. After that print 4k numbers --- the lines that should form the poem.

There should be an empty line after each case.

Sample Input

151 2 3 1 2 1 2 3 3 2 1 1 3 2 231 2 3

Sample Output

31 2 4 57 8 9 1011 12 14 150

Source: 
Andrew Stankevich's Contest #9

#include 
#include
#include
#include
#include
using namespace std;const int maxn=4400;int n;vector
v[maxn];vector
ans;void init(){ for(int i=0; i<=n+10; i++) v[i].clear(); ans.clear();}int a[maxn],b[maxn];int main(){ bool first=true; while(scanf("%d",&n)!=EOF) { if(first) first=false; else putchar(10); init(); for(int i=0; i
=2) { if(two!=-1) { if(two!=a[i]) { ans.push_back(v[two][0]); ans.push_back(v[two][1]); ans.push_back(v[a[i]][0]); ans.push_back(v[a[i]][1]); /// clear for(int j=0; j<=n+10; j++) v[j].clear(); two=-1; } else if(two==a[i]&&vas>=4) { for(int j=0;j<4;j++) { ans.push_back(v[a[i]][j]); } for(int j=0; j<=n+10; j++) v[j].clear(); two=-1; } } else { two=a[i]; } } } printf("%d\n",(int)ans.size()/4); sort(ans.begin(),ans.end()); for(int i=0,sz=ans.size();i

转载地址:http://xxtbo.baihongyu.com/

你可能感兴趣的文章
freeBSD安装详细讲解
查看>>
WSFC2016 VM弹性与存储容错
查看>>
文档管理,文本编辑控件TX Text Control .NET for WPF
查看>>
复习 Python 匿名函数 内建函数
查看>>
Security Identifiers | Win SRV2016 SID Change 修改
查看>>
看看来自日本的扫描,做网站需要注意的
查看>>
JDK 1.7+Android SDK+IntelliJ IDEA 13+Genymotion 安卓开发环境部署
查看>>
钓鱼邮件***防范指南
查看>>
session_start()放置位置的不正确引发的ROOT常量 未定义的错误
查看>>
如何设定VDP同时备份的任务数?
查看>>
ipsec的***在企业网中的经典应用
查看>>
过来人谈《去360还是留在百度?》
查看>>
mysql备份工具innobackupex,xtrabackup-2.1安装,参数详解
查看>>
【复制】slave筛选复制之二(create/drop table语句)
查看>>
Movie Store OpenCart 自适应主题模板 ABC-0249
查看>>
mytop-MySQL监控工具
查看>>
RedHat linux YUM本地制作源
查看>>
apache端口占用问题
查看>>
本地Office Project计划表同步到SharePoint2013任务列表的权限问题
查看>>
Windows2008 R2 GAC权限问题
查看>>