题目描述

N (1 <= N <= 50,000) cows conveniently numbered 1..N are driving in separate cars along a highway in Cowtopia. Cow i can drive in any of M different high lanes (1 <= M <= N) and can travel at a maximum speed of S_i (1 <= S_i <= 1,000,000) km/hour.

After their other bad driving experience, the cows hate collisions and take extraordinary measures to avoid them. On this highway, cow i reduces its speed by D (0 <= D <= 5,000) km/hour for each cow in front of it on the highway (though never below 0 km/hour). Thus, if there are K cows in front of cow i, the cow will travel at a speed of max[S_i - D * K, 0]. While a cow might actually travel faster than a cow directly in front of it, the cows are spaced far enough apart so crashes will not occur once cows slow down as

described,

Cowtopia has a minimum speed law which requires everyone on the highway to travel at a a minimum speed of L (1 <= L <= 1,000,000) km/hour so sometimes some of the cows will be unable to take the highway if they follow the rules above. Write a program that will find the maximum number of cows that can drive on the highway while obeying the minimum speed limit law.

编号为1到N的N只奶牛正各自驾着车打算在牛德比亚的高速公路上飞驰.高速公路有M(1≤M≤N)条车道.奶牛i有一个自己的车速上限Si(l≤Si≤1,000,000).

在经历过糟糕的驾驶事故之后,奶牛们变得十分小心,避免碰撞的发生.每条车道上,如果某一只奶牛i的前面有南只奶牛驾车行驶,那奶牛i的速度上限就会下降kD个单位,也就是说,她的速度不会超过Si – kD(O≤D≤5000),当然如果这个数是负的,那她的速度将是0.牛德比亚的高速会路法规定,在高速公路上行驶的车辆时速不得低于/(1≤L≤1,000,000).那么,请你计算有多少奶牛可以在高速公路上行驶呢?

输入输出格式

输入格式:

  • Line 1: Four space-separated integers: N, M, D, and L

  • Lines 2..N+1: Line i+1 describes cow i's initial speed with a single integer: S_i

输出格式:

  • Line 1: A single integer representing the maximum number of cows that can use the highway

输入输出样例

输入样例#1:
复制

3 1 1 5
5
7
5
输出样例#1: 复制

2

说明

There are three cows with one lane to drive on, a speed decrease of 1, and a minimum speed limit of 5.

Two cows are possible, by putting either cow with speed 5 first and the cow with speed 7 second.

思路

从小到大排序,然后贪心选择车道;

代码

 #include<cstdio>
#include<algorithm>
#define LL long long
const int maxn=1e5+;
LL n,m,ans;
struct nate{LL t,d;}s[maxn];
bool comp(nate x,nate y){return x.t*y.d<x.d*y.t;}
int main(){
scanf("%lld",&n);
for(int i=;i<=n;i++){
scanf("%lld%lld",&s[i].t,&s[i].d);
s[i].t*=,m+=s[i].d;
}
std::sort(s+,s+n+,comp);
for(int i=;i<=n;i++){
m-=s[i].d;
ans+=s[i].t*m;
}
printf("%lld\n",ans);
return ;
}

[USACO08OPEN]牛的车Cow Cars的更多相关文章

  1. bzoj1623 / P2909 [USACO08OPEN]牛的车Cow Cars

    P2909 [USACO08OPEN]牛的车Cow Cars 显然的贪心. 按速度从小到大排序.然后找车最少的车道,查询是否能填充进去. #include<iostream> #inclu ...

  2. 洛谷 P2909 [USACO08OPEN]牛的车Cow Cars

    传送门 题目大意: m个车道. 如果第i头牛前面有k头牛,那么这头牛的最大速度会 变为原本的速度-k*D,如果速度小于l这头牛就不能行驶. 题解:贪心 让初始速度小的牛在前面 代码: #include ...

  3. bzoj1604 / P2906 [USACO08OPEN]牛的街区Cow Neighborhoods

    P2906 [USACO08OPEN]牛的街区Cow Neighborhoods 考虑维护曼哈顿距离:$\left | x_{1}-x_{2} \right |+\left | y_{1}-y_{2} ...

  4. 「洛谷P2906」[USACO08OPEN]牛的街区Cow Neighborhoods 解题报告

    P2906 [USACO08OPEN]牛的街区Cow Neighborhoods 题目描述 Those Who Know About Cows are aware of the way cows gr ...

  5. P2906 [USACO08OPEN]牛的街区Cow Neighborhoods

    传送门 曼哈顿距离好像不好直接算,我们可以把牛的坐标转化一下以方便计算距离 (x,y) --> (x+y,x-y) 那么距离就可以表示成 $max(\left |x_1-x_2  \right ...

  6. 洛谷 P2906 [USACO08OPEN]牛的街区Cow Neighborhoods | Set+并查集

    题目: https://www.luogu.org/problemnew/show/P2906 题解: 垃圾水题 #include<cstdio> #include<algorith ...

  7. [USACO08OPEN]牛的街区Cow Neighborhoods

    题目描述: luogu 题解: 技巧题. 曼哈顿距离:$|x1-x2|+|y1-y2|$ 切比雪夫距离:$\max(|x1-x2|,|y1-y2|)$ 曼哈顿距离转切比雪夫距离:$(x,y)-> ...

  8. USACO Cow Cars

    洛谷 P2909 [USACO08OPEN]牛的车Cow Cars https://www.luogu.org/problemnew/show/P2909 JDOJ 2584: USACO 2008 ...

  9. bzoj1649 / P2854 [USACO06DEC]牛的过山车Cow Roller Coaster

    P2854 [USACO06DEC]牛的过山车Cow Roller Coaster dp 对铁轨按左端点排个序,蓝后就是普通的二维dp了. 设$d[i][j]$为当前位置$i$,成本为$j$的最小花费 ...

随机推荐

  1. memcache的分布式配置

    public static class MemcacheHelper { private static MemcachedClient mc; static MemcacheHelper() { St ...

  2. Android程序打包为APK

    Andriod安装包文件(Android Package),简称APK,后缀名为.apk. 1.生成未签名的安装包 Build -> Build Bundle(s)/APK(s) -> B ...

  3. spring事务问题

    springmvc中在service层中有如下逻辑:1.提交事务2.开启新线程,新线程中的业务依赖1中提交的事务处理办法:在service中新建一个方法do,调本地提交事务的方法doTranction ...

  4. Java 11 正式发布,支持期限至2026年9月

    美国当地时间9月25日,Oracle 官方宣布 Java 11 (18.9 LTS) 正式发布,可在生产环境中使用!这是自 Java 8 后的首个长期支持版本,非常值得大家的关注,可以通过下面的地址进 ...

  5. wkWebView 的一些问题

    导语 WKWebView 是苹果在 WWDC 2014 上推出的新一代 webView 组件,用以替代 UIKit 中笨重难用.内存泄漏的 UIWebView.WKWebView 拥有60fps滚动刷 ...

  6. iOS 应用程序内部国际化,不跟随系统语言

    前言:网络上关于iOS国际化的文章很多,但基本上都是基于跟随系统语言的国际化,笔者就不赘述了-0 – 今天要讲的是不跟随系统的切换语言版本方案,即程序内部的切换语言版本方案. 一.总则: 应用内部语言 ...

  7. Eclipse添加默认的JRE

    打开eclipse,依次点击如下选项Window->Preferences-> Java -> Installed JREs.步骤见下图.   选中Installed JREs选项出 ...

  8. Dart开发环境搭建

    一.SDK的安装与环境配置 1. 下载Dark SDK http://www.gekorm.com/dart-windows/ 2.  安装SDK 3.  配置环境变量(一般已经默认生成好了,这里可以 ...

  9. Windows虚拟桌面

    PROCESS_INFORMATION ProcessInfo; STARTUPINFO StartupInfo; HDESK hDesktop; HDESK hOriginalThread; HDE ...

  10. python基础:函数传参、全局变量、局部变量、内置函数、匿名函数、递归、os模块、time模块

    ---恢复内容开始--- 一.函数相关: 1.1位置参数: ef hello(name,sex,county='china'): pass #hello('hh','nv') #位置参数.默认参数 1 ...