zoukankan      html  css  js  c++  java
  • Codeforces Round #461 (Div. 2) DRobot Vacuum Cleaner

    Pushok the dog has been chasing Imp for a few hours already.

    Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner.

    While moving, the robot generates a string t consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string t as the number of occurrences of string "sh" as a subsequence in it, in other words, the number of such pairs (i, j), that i < j and and .

    The robot is off at the moment. Imp knows that it has a sequence of strings ti in its memory, and he can arbitrary change their order. When the robot is started, it generates the string t as a concatenation of these strings in the given order. The noise of the resulting string equals the noise of this concatenation.

    Help Imp to find the maximum noise he can achieve by changing the order of the strings.

    Input

    The first line contains a single integer n (1 ≤ n ≤ 105) — the number of strings in robot's memory.

    Next n lines contain the strings t1, t2, ..., tn, one per line. It is guaranteed that the strings are non-empty, contain only English letters 's' and 'h' and their total length does not exceed 105.

    Output

    Print a single integer — the maxumum possible noise Imp can achieve by changing the order of the strings.

    Examples
    Input
    Copy
    4
    ssh
    hs
    s
    hhhs
    Output
    Copy
    18
    Input
    Copy
    2
    h
    s
    Output
    Copy
    1
    Note

    The optimal concatenation in the first sample is ssshhshhhs.

    给定n个字符串,每个字符串有若干个字符's'和'h',n个字符串可以随意组合,求组合后的sh的最大值

    快排的排序自定义问题,字符串a和b ,求a+b和b+a的值分别时多少,多的优先。

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int N = 1e5+10;
    string s[N], ss;
    ll count(string s) {
    	ll ans = 0, tmp = 0;
    	for(int i = 0; i < s.length(); i ++) {
    		if(s[i] == 's') tmp++;
    		else if(s[i] == 'h') ans += tmp;
    	}
    	return ans;
    }
    bool cmp(string &a, string &b) {
    	return count(a+b) > count(b+a);
    }
    int main() {
    	int n;
    	cin >> n;
    	for(int i = 0; i < n; i ++) cin >> s[i];
    	sort(s,s+n,cmp);
    	for(int i = 0; i < n; i ++) ss += s[i];
    	cout << count(ss) <<endl;
    	return 0;
    }
    
  • 相关阅读:
    使用binlog恢复数据
    Xtrabackup增量差量备份
    解压腾讯DB冷备的xb文件
    mysqldump
    xtrabackup备份选项
    MySQL的各种日志
    MySQL的事务相关概念
    LVS(dr)+keepalived
    MeasureSpec学习
    网络通信机制:Socket、TCP/IP、HTTP
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8821882.html
Copyright © 2011-2022 走看看