ZOJ 3700 Ever Dream

本文分享了一首名为《EverDream》的金属乐歌曲及其歌词所蕴含的情感,并介绍了一个简单的算法,该算法能够从歌曲中提取关键词,以此来表达歌曲的意义。通过分析歌词并运用特定算法,最终输出了这首歌曲的代表性词汇。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



"Ever Dream" played by Nightwish is my favorite metal music. The lyric (see Sample Input) of this song is much more like a poem. Every people may have their own interpretation for this song depending on their own experience in the past. For me, it is a song about pure and unrequited love filled with innocence, willingness and happiness. I believe most people used to have or still have a long story with someone special or something special. However, perhaps fatefully, life is totally a joke for us. One day, the story ended and became a dream in the long night that would never come true. The song touches my heart because it reminds me the dream I ever had and the one I ever loved.

Today I recommend this song to my friends and hope that you can follow your heart. I also designed a simple algorithm to express the meaning of a song by several key words. There are only 3 steps in this algorithm, which are described below:

Step 1: Extract all different words from the song and counts the occurrences of each word. A word only consists of English letters and it is case-insensitive.

Step 2: Divide the words into different groups according to their frequencies (i.e. the number of times a word occurs). Words with the same frequency belong to the same group. 

Step 3: For each group, output the word with the longest length. If there is a tie, sort these words (not including the words with shorter length) in alphabetical order and output the penultimate one. Here "penultimate" means the second to the last. The word with higher frequency should be output first and you don't need to output the word that just occurs once in the song. 

Now given the lyric of a song, please output its key words by implementing the algorithm above.

Input

The first line of input is an integer T (T < 50) indicating the number of test cases. For each case, first there is a line containing the number n (n < 50) indicating that there are n lines of words for the song. The following n lines contain the lyric of the song. An empty line is also counted as a single line. Any ASCII code can occur in the lyric. There will be at most 100 characters in a single line.

Output

For each case, output the key words in a single line. Words should be in lower-case and separated by a space. If there is no key word, just output an empty line.

Sample Input
1
29
Ever felt away with me 
Just once that all I need 
Entwined in finding you one day 

Ever felt away without me 
My love, it lies so deep 
Ever dream of me 

Would you do it with me 
Heal the scars and change the stars 
Would you do it for me 
Turn loose the heaven within 

I'd take you away 
Castaway on a lonely day 
Bosom for a teary cheek 
My song can but borrow your grace 

Come out, come out wherever you are 
So lost in your sea 
Give in, give in for my touch 
For my taste for my lust 

Your beauty cascaded on me 
In this white night fantasy 

"All I ever craved were the two dreams I shared with you. 
One I now have, will the other one ever dream remain. 
For yours I truly wish to be." 

Sample Output
for ever with dream

简单的模拟题,找出单词排序输出即可。
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
int T,n;
char s[N];
map<string,int> M;
pair<int,string> g[N];

bool cmp(pair<int,string> a,pair<int,string> b)
{
    if (a.first!=b.first) return a.first>b.first;
    if (a.second.size()!=b.second.size()) return a.second.size()>b.second.size();
    return a.second>b.second;
}

int main()
{
    for (scanf("%d",&T);T--;)
    {
        scanf("%d",&n); getchar(); M.clear();
        for (int i=1;i<=n;i++)
        {
            gets(s);
            string g="";
            for (int j=0;s[j];j++)
            {
                if (s[j]>='A'&&s[j]<='Z') s[j]+=32;
                if (s[j]>='a'&&s[j]<='z') g+=s[j];
                if (s[j]<'a'||s[j]>'z'||!s[j+1])
                    if (g!="") M[g]++,g="";
            }
        }
        int sz=0;
        for (map<string,int>::iterator it=M.begin();it!=M.end();it++)
        {
            if (it->second>1) g[sz++]=make_pair(it->second,it->first);
        }
        sort(g,g+sz,cmp);
        int flag=0;
        for (int i=0,j;i<sz;i=j)
        {
            if (flag) printf(" "); else flag=1;
            for (j=i;g[i].first==g[j].first&&j<sz;j++);
            if (j==i+1) cout<<g[i].second;
            else if (g[i].second.size()==g[i+1].second.size())
            {
                cout<<g[i+1].second;
            }
            else cout<<g[i].second;
        }
        putchar(10);
    }
    return 0;
}


内容概要:该论文研究增程式电动汽车(REEV)的能量管理策略,针对现有优化策略实时性差的问题,提出基于工况识别的自适应等效燃油消耗最小策略(A-ECMS)。首先建立整车Simulink模型和基于规则的策略;然后研究动态规划(DP)算法和等效燃油最小策略;接着通过聚类分析将道路工况分为四类,并设计工况识别算法;最后开发基于工况识别的A-ECMS,通过高德地图预判工况类型并自适应调整SOC分配。仿真显示该策略比规则策略节油8%,比简单SOC规划策略节油2%,并通过硬件在环实验验证了实时可行性。 适合人群:具备一定编程基础,特别是对电动汽车能量管理策略有兴趣的研发人员和技术爱好者。 使用场景及目标:①理解增程式电动汽车能量管理策略的基本原理;②掌握动态规划算法和等效燃油消耗最小策略的应用;③学习工况识别算法的设计和实现;④了解基于工况识别的A-ECMS策略的具体实现及其优化效果。 其他说明:此资源不仅提供了详细的MATLAB/Simulink代码实现,还深入分析了各算法的原理和应用场景,适合用于学术研究和工业实践。在学习过程中,建议结合代码调试和实际数据进行实践,以便更好地理解策略的优化效果。此外,论文还探讨了未来的研究方向,如深度学习替代聚类、多目标优化以及V2X集成等,为后续研究提供了思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值