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

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. spring cloud微服务实践二

    在上一篇,我们已经搭建了spring cloud微服务中的注册中心.但只有一个注册中心还远远不够. 接下来我们就来尝试提供服务. 注:这一个系列的开发环境版本为 java1.8, spring boo ...

  2. hadoop2.7.7 分布式集群安装与配置

    环境准备 服务器四台: 系统信息 角色 hostname IP地址 Centos7.4 Mster hadoop-master-001 10.0.15.100 Centos7.4 Slave hado ...

  3. SpringBoot 第一篇:HelloWorld 跑起来

    背景 金融行业从业快十年,作为银行系开发人员来说开源框架了解不多非常正常,因为银行系的运行平台,基本上不会采购小厂商集合开源框架自建的产品,竞标的产品没有几十个成功案例,你也进不了这个门槛(有关系的除 ...

  4. win7+cuda+anaconda python+tensorflow-gpu+keras安装成功版本匹配汇总

    win7+cuda+anaconda python+tensorflow-gpu+keras安装成功版本匹配汇总 2019-09-20 15:06:03 wyx100 阅读数 38更多 分类专栏: M ...

  5. linux下通过vim编辑文件的方法

    一般来说是通过指令进入文件的编辑页面: vi [filename] 此时进入的是一般指令模式,然后可以直接移动光标对内容进行修改. 修改完成后,使用Esc 按键退出编辑模式. 此时回到的还是一般指令模 ...

  6. Apache2.4+Tomcat7.0+php5.5整合配置详解

    在上一篇的基础上,继续添加php的配置 一.首先下载php5.5 首先下载php5.5,到官网下载http://www.php.net/downloads.php,参考http://www.cnblo ...

  7. PAT-1001 A+B Format (20 分) 注意零的特例

    Calculate a+b and output the sum in standard format -- that is, the digits must be separated into gr ...

  8. 重构与反思-<重构代码的7个阶段>有感

    https://coolshell.cn/articles/5201.html/comment-page-2#comment-1932554 过去半年基本上完整经历了这个文章的各个阶段,看完文章结合自 ...

  9. vue的自定义指令

    点击元素之外触发函数 <template> <div v-clickoutside="clickItemOut"></div> </tem ...

  10. 前端编译原理 简述-jison

    最近几年的项目技术难点都和编译原理,抽象语法树,代码编辑器 有关系.现在时间有点空,先从基础了解起来,让有些交互和提示能够更智能些. 编译原理-Parser    编译原理 其实就是 让计算机懂的 “ ...