[USACO08OPEN]牛的车Cow Cars

题目描述

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.

思路

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

代码

 1 #include<cstdio>
 2 #include<algorithm>
 3 #define LL long long
 4 const int maxn=1e5+10;
 5 LL n,m,ans;
 6 struct nate{LL t,d;}s[maxn];
 7 bool comp(nate x,nate y){return x.t*y.d<x.d*y.t;}
 8 int main(){
 9     scanf("%lld",&n);
10     for(int i=1;i<=n;i++){
11         scanf("%lld%lld",&s[i].t,&s[i].d);
12         s[i].t*=2,m+=s[i].d;
13     }
14     std::sort(s+1,s+n+1,comp);
15     for(int i=1;i<=n;i++){
16         m-=s[i].d;
17         ans+=s[i].t*m;
18     }
19     printf("%lld\n",ans);
20     return 0;
21 }
时间: 2024-11-02 15:54:09

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

洛谷 P2909 [USACO08OPEN]牛的车Cow Cars

P2909 [USACO08OPEN]牛的车Cow Cars 题目描述 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

洛谷P2906 [USACO08OPEN]牛的街区Cow Neighborhoods

曼哈顿距离转切比雪夫距离 1 #include <bits/stdc++.h> 2 #define LL long long 3 #define GG int 4 #define For(i, j, k) for(register int i=j; i<=k; i++) 5 #define Dow(i, j, k) for(register int i=j; i>=k; i--) 6 using namespace std; 7 GG read() { 8 GG x = 0, f

[USACO08OPEN]牛的街区Cow Neighborhoods

题目描述: luogu 题解: 技巧题. 曼哈顿距离:$|x1-x2|+|y1-y2|$ 切比雪夫距离:$\max(|x1-x2|,|y1-y2|)$ 曼哈顿距离转切比雪夫距离:$(x,y)->(x+y,x-y)$ 所以……排完序拿stl::set模拟就好了. 代码: #include<set> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typ

【题解】P2854 [USACO06DEC]牛的过山车Cow Roller Coaster

P2854 [USACO06DEC]牛的过山车Cow Roller Coaster 题目描述 The cows are building a roller coaster! They want your help to design as fun a roller coaster as possible, while keeping to the budget. The roller coaster will be built on a long linear stretch of land o

bzoj 1623: [Usaco2008 Open]Cow Cars 奶牛飞车

1623: [Usaco2008 Open]Cow Cars 奶牛飞车 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 325  Solved: 223[Submit][Status][Discuss] Description 编号为1到N的N只奶牛正各自驾着车打算在牛德比亚的高速公路上飞驰.高速公路有M(1≤M≤N)条车道.奶牛i有一个自己的车速上限Si(l≤Si≤1,000,000). 在经历过糟糕的驾驶事故之后,奶牛们变得十分小心,避免碰撞的发生

1623: [Usaco2008 Open]Cow Cars 奶牛飞车

1623: [Usaco2008 Open]Cow Cars 奶牛飞车 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 291  Solved: 201[Submit][Status][Discuss] Description 编号为1到N的N只奶牛正各自驾着车打算在牛德比亚的高速公路上飞驰.高速公路有M(1≤M≤N)条车道.奶牛i有一个自己的车速上限Si(l≤Si≤1,000,000). 在经历过糟糕的驾驶事故之后,奶牛们变得十分小心,避免碰撞的发生

P2966 [USACO09DEC]牛收费路径Cow Toll Paths

P2966 [USACO09DEC]牛收费路径Cow Toll Paths 题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm. The cows mo

编程算法 - 最好牛线(Best Cow Line) 代码(C)

最好牛线(Best Cow Line) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 给定长度为N的字符串S, 要构造一个长度为N的字符串T. 反复进行如下任意操作. 从S的头部删除一个字符, 放入T的尾部; 从S的尾部删除一个字符, 放入T的尾部; 目标是要构造字典序尽可能小的字符串T. 使用贪心算法, 不断选取S首尾最小的字符, 放入T, 如果相等, 则再次向内查找, 找到内部最小的. 代码: /* * main.cpp * * Cr

老二牛Axure车夜话: Axure手机原型视频教程汇总贴

老二牛Axure车夜话: Axure手机原型视频教程汇总贴 Axure手机原型视频教程汇总贴 Axure手机原型视频教程之图形解锁 Axure手机原型视频教程之侧滑菜单(抽屉导航) Axure手机原型视频教程之Path2.0菜单 Axure手机原型视频教程之微信公众ETC菜单与输入 Axure手机原型视频教程之微信公众ETC添加公众号 Axure手机原型课程介绍汇总 Axure手机应用原型课程案例介绍 Axure手机原型课程案例微信公众ETC关键字菜单思维导图mmap Axure手机原型课程案例