admin管理员组文章数量:1630193
Des:
Doki Doki Literature Club! is a visual novel developed by Team Salvato. The protagonist is invited by his childhood friend, Sayori, to join their high school’s literature club. The protagonist then meets the other members of the club: Natsuki, Yuri, and the club president Monika. The protagonist starts to participate in the club’s activities such as writing and sharing poetry, and grows close to the four girls. What a lovely story!
A very important feature of the game is its poetry writing mechanism. The player is given a list of various words to select from that will make up his poem. Each girl in the Literature Club has different word preferences, and will be very happy if the player’s poem is full of her favorite words.
BaoBao is a big fan of the game and likes Sayori the most, so he decides to write a poem to please Sayori. A poem of mmwords s1,s2,…,sms1,s2,…,sm is nothing more than a sequence of mm strings, and the happiness of Sayori after reading the poem is calculated by the formula.
where HH is the happiness and f(si)f(si) is Sayori’s preference to the word sisi .
Given a list of nn words and Sayori’s preference to each word, please help BaoBao select mm words from the list and finish the poem with these mm words to maximize the happiness of Sayori.
Please note that each word can be used at most once!
Input
There are multiple test cases. The first line of input contains an integer TT (about 100), indicating the number of test cases. For each test case:
The first line contains two integers nn and mm (1≤m≤n≤1001≤m≤n≤100), indicating the number of words and the length of the poem.
For the following nn lines, the ii-th line contains a string consisting of lowercased English letters wiwi (1≤|wi|≤151≤|wi|≤15) and an integer f(wi)f(wi) (−109≤f(wi)≤109−109≤f(wi)≤109), indicating the ii-th word and Sayori’s preference to this word. It’s guaranteed that wi≠wjwi≠wj for all i≠ji≠j.
Output
For each test case output one line containing an integer HH and mm strings s1,s2,…,sms1,s2,…,sm separated by one space, indicating the maximum possible happiness and the corresponding poem. If there are multiple poems which can achieve the maximum happiness, print the lexicographically smallest one.
Please, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect!
A sequence of mm strings a1,a2,…,ama1,a2,…,am is lexicographically smaller than another sequence of mm strings b1,b2,…,bmb1,b2,…,bm, if there exists a kk (1≤k≤m1≤k≤m) such that ai=biai=bi for all 1≤i<k1≤i<k and akak is lexicographically smaller than bkbk.
A string s1=a1a2…axs1=a1a2…ax is lexicographically smaller than another string s2=b1b2…bys2=b1b2…by, if there exists a kk (1≤k≤min(x,y)1≤k≤min(x,y)) such that ai=biai=bi for all 1≤i<k1≤i<k and ak<bkak<bk, or ai=biai=bi for all 1≤i≤min(x,y)1≤i≤min(x,y) and x<yx<y.
就是一个排序然后输出问题,先按数的大小排序,如果输大小一样,按字符串的大小比较.
看代码
# include <stdio.h>
# include <string.h>
struct qwe
{
char mame[20];
long long chengji;
};
int main(void)
{
int t, m, n, i, j;
struct qwe a[110], y;
long long sum;
scanf("%d", &t);
while (t --)
{
scanf("%d %d", &n, &m);
for (i = 1; i <= n; i ++)
scanf("%s %lld", a[i].mame, &a[i].chengji);
for (i = 1; i <= n-1; i ++)
for (j = i+1; j <= n; j ++)
if (a[i].chengji < a[j].chengji || (a[i].chengji == a[j].chengji && strcmp(a[i].mame, a[j].mame) > 0))
{
y = a[i];
a[i] = a[j];
a[j] = y;
}
sum = 0;
for (i = 1; i <= m; i ++)
{
sum = sum + a[i].chengji*(m-i+1);
}
printf("%lld ", sum);
for (i = 1; i <= m; i ++)
if (i == m)
printf("%s", a[i].mame);
else
printf("%s ",a[i].mame);
printf("\n");
}
return 0;
}
本文标签: ACMZJPproClubLiterature
版权声明:本文标题:15th ZJP Acm - Pro L. Doki Doki Literature Club 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729056525a1184031.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论