正确的贪心方法:按照比例排序.

code:

#include <bits/stdc++.h>
#define N 200000
#define ll long long
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int n;
char str[N],S[N];
struct Node
{
int l,r;
double perc;
}t[N];
bool cmp(Node a,Node b)
{
return a.perc>b.perc;
}
int main()
{
int i,j,cnt=0;
// msetIO("input");
scanf("%d",&n);
for(i=1;i<=n;++i)
{
scanf("%s",str+1);
int len=strlen(str+1),s=0;
t[i].l=cnt+1;
for(j=1;j<=len;++j) ++cnt, S[cnt]=str[j],s+=(str[j]=='s');
t[i].r=cnt;
t[i].perc=(double)s/len;
}
ll pre=0,ans=0;
sort(t+1,t+1+n,cmp);
for(i=1;i<=n;++i)
{
int l=t[i].l;
int r=t[i].r;
for(j=l;j<=r;++j)
{
if(S[j]=='s')
{
++pre;
}
else
{
ans+=pre;
}
}
}
printf("%lld\n",ans);
return 0;
}

  

CF922D Robot Vacuum Cleaner 贪心+排序的更多相关文章

  1. Codeforces 922 C - Robot Vacuum Cleaner (贪心、数据结构、sort中的cmp)

    题目链接:点击打开链接 Pushok the dog has been chasing Imp for a few hours already. Fortunately, Imp knows that ...

  2. CodeForces - 922D Robot Vacuum Cleaner (贪心)

    Pushok the dog has been chasing Imp for a few hours already. Fortunately, Imp knows that Pushok is a ...

  3. Codeforces Round #461 (Div. 2) D. Robot Vacuum Cleaner

    D. Robot Vacuum Cleaner time limit per test 1 second memory limit per test 256 megabytes Problem Des ...

  4. 【Codeforces 922D】Robot Vacuum Cleaner

    [链接] 我是链接,点我呀:) [题意] 让你把n个字符串重新排序,然后按顺序连接在一起 使得这个组成的字符串的"sh"子序列最多 [题解] /* * 假设A的情况好于B * 也就 ...

  5. 489. Robot Room Cleaner扫地机器人

    [抄题]: Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or block ...

  6. HDU 4442 Physical Examination(关于贪心排序)

    这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1, ...

  7. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. [LeetCode] Robot Room Cleaner 扫地机器人

    Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. Th ...

  9. LeetCode - Robot Room Cleaner

    Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. Th ...

随机推荐

  1. 关于scanf()读取与返回值和回车键的问题

    今天老师检查的时候说如果一个链表为空(简单的说就是while(scanf())一开始没输入数字就按回车的话会进入死循环)的情况, 我当时有点懵,因为文档里强调为空的情况.还好老师叫我自己现场实现一下, ...

  2. Redis的bind的误区(转)

    原文1:https://blog.csdn.net/cw_hello1/article/details/83444013 原文2:https://www.cnblogs.com/suiyueqiann ...

  3. Node初始以及环境搭建(Node01)

    1. 相关概念 •什么是JavaScript? •一种遵守ECMAScript标准的脚本语言 •最初只能运行在浏览器端 •浏览器中的 JavaScript 可以做什么? •操作DOM:表单验证.动画 ...

  4. ndk-build 修改输出so位置 (change ndk-build output so lib file path )

    期望的目录结构: Folder --- | --- build.bat | --- Source | --- All sources codes *.cpp *.h | --- Android --- ...

  5. 【vue开发】vue插件的install方法

    MyPlugin.install = function (Vue, options) { // 1. 添加全局方法或属性 Vue.myGlobalMethod = function () { // 逻 ...

  6. The openssl extension is missing, which means that secure HTTPS transfers are impossible

    执行命令:curl -sS https://getcomposer.org/installer | php报错如下Some settings on your machine make Composer ...

  7. Centos超详细安装步骤

    Linux中三大主流操作系统 Ubuntu 优点:用户界面友好.工具完善 缺点:vps(虚拟服务器)成本较高.不具备商业化服务器操作系统 Centos--目前常用centos6.x,centos7.x ...

  8. MySQL数字类型int与tinyint、float与decimal如何选择

    最近在准备给开发做一个mysql数据库开发规范方面培训,一步一步来,结合在生产环境发现的数据库方面的问题,从几个常用的数据类型说起. int.tinyint与bigint 它们都是(精确)整型数据类型 ...

  9. 3.Vue过滤器

    1.概念: Vue.js 允许你自定义过滤器,可被用作一些常见文本的格式化,过滤器可以用在两个地方:mustache 插值和 v-bind 表达式.过滤器应该被添加在 JavaScript 表达式的尾 ...

  10. springboot的简单了解与使用

    1. Spring Boot 1.1. 什么是Spring Boot 1.2. Spring Boot的优缺点 1.3. 快速入门 1.3.1. 设置spring boot的parent <pa ...