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

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. Nuget常用命令(转)

    转自:https://www.cnblogs.com/xcsn/p/6259853.html CMD将nuget升级到最新版本:nuget update -self 一.安装 1.安装指定版本类库in ...

  2. (十五)Activitivi5之多用户任务分配

    一.概念 我们在开发的时候,有一种情况是这样的, 我们有一个任务,可以让多个用户中的任何一个人办理即可,比如某个审批任务, 张三,李四,王五他们中的任何一人办理下都行,这时候,我们用到多用户任务分配. ...

  3. (五)CXF之添加拦截器

    一.需求分析 webService中的拦截器类似于servlet的Filter过滤器.一般用于调用服务前后先调用拦截器的方法. 二.案例 本章案例是基于上一章节的基础上添加拦截器的 2.1 服务端添加 ...

  4. 经典SQL数据库面试题以及答案—Oracle版本-SQL全部在plsql开发编写-欢迎提问

    Student(Sno,Sname,Sage,Ssex) 学生表 S1:学号:Sname:学生姓名:Sage:学生年龄:Ssex:学生性别 Course(Cno,Cname,T1) 课程表 C1,课程 ...

  5. 安装window、linux双系统

    一.安装windows,从主硬盘中分出40G空间: 二.下载linux ios镜像; 三.安装UltraISO,把下载好的linux镜像写入u盘: ‘写入硬盘镜像’->写入方式‘usb-HDD+ ...

  6. MySql Host is blocked because of many connection errors 问题的解决方法

    错误日志: message from server: "Host '10.250.112.141' is blocked because of many connection errors; ...

  7. 运行 jar 的问题

    lib stwe.jar 同目录

  8. 装机篇:ubuntu 14.04 在英文环境下安装中文输入法(转载)

    ubuntu默认的输入法是ibus,综合网上评论,fcitx的支持者更多,而且个人感觉fcitx也的确不错,可以满足日常输入. STEP1: 在Ubuntu Software Center 搜索fci ...

  9. django中解决跨域问题

    -跨域问题 -浏览器的:同源策略,浏览器拒绝不是当前域域返回的数据 -ip地址和端口号都相同才是同一个域 -如何解决: -CORS:跨域资源共享 -简单请求:发一次请求 -非简单请求:非简单请求是发送 ...

  10. 如何利用while语句打印“九九乘法口诀表”

    需求:输出九九乘法表 plus.py代码如下: i=1 j=1 while i<=9: j=1 while j<=i: print(j,'*',i,'=',str(i*j)+' ',end ...