Codeforces Bayan 2012-2013 Elimination Round / 241A Old Peykan (贪心)
2013-08-28 16:15
344 查看
A. Old Peykan
http://codeforces.com/contest/241/problem/A
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn.
The Old Peykan wants to travel from city c1 to cn using
roads. There are (n - 1) one way roads, the i-th
road goes from city ci to
city ci + 1 and
is di kilometers
long.
The Old Peykan travels 1 kilometer in 1 hour and consumes 1 liter of fuel during this time.
Each city ci (except
for the last city cn)
has a supply of si liters
of fuel which immediately transfers to the Old Peykan if it passes the city or stays in it. This supply refreshes instantly k hours after it transfers.
The Old Peykan can stay in a city for a while and fill its fuel tank many times.
Initially (at time zero) the Old Peykan is at city c1 and s1 liters
of fuel is transferred to it's empty tank from c1's
supply. The Old Peykan's fuel tank capacity is unlimited. Old Peykan can not continue its travel if its tank is emptied strictly between two cities.
Find the minimum time the Old Peykan needs to reach city cn.
Input
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000).
The value m specifies the number of roads between cities which is equal to n - 1.
The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and
the following line contains m space-separated integers s1, s2, ..., sm (1 ≤ si ≤ 1000).
Output
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from
city c1.
Sample test(s)
input
output
input
output
Note
In the second sample above, the Old Peykan stays in c1 for
3 hours.
贪心思路:在s[i]最大的城市加最多的油,详见代码。
完整代码:
http://codeforces.com/contest/241/problem/A
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn.
The Old Peykan wants to travel from city c1 to cn using
roads. There are (n - 1) one way roads, the i-th
road goes from city ci to
city ci + 1 and
is di kilometers
long.
The Old Peykan travels 1 kilometer in 1 hour and consumes 1 liter of fuel during this time.
Each city ci (except
for the last city cn)
has a supply of si liters
of fuel which immediately transfers to the Old Peykan if it passes the city or stays in it. This supply refreshes instantly k hours after it transfers.
The Old Peykan can stay in a city for a while and fill its fuel tank many times.
Initially (at time zero) the Old Peykan is at city c1 and s1 liters
of fuel is transferred to it's empty tank from c1's
supply. The Old Peykan's fuel tank capacity is unlimited. Old Peykan can not continue its travel if its tank is emptied strictly between two cities.
Find the minimum time the Old Peykan needs to reach city cn.
Input
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000).
The value m specifies the number of roads between cities which is equal to n - 1.
The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and
the following line contains m space-separated integers s1, s2, ..., sm (1 ≤ si ≤ 1000).
Output
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from
city c1.
Sample test(s)
input
4 6 1 2 5 2 2 3 3 4
output
10
input
2 3 5 6 5 5
output
14
Note
In the second sample above, the Old Peykan stays in c1 for
3 hours.
贪心思路:在s[i]最大的城市加最多的油,详见代码。
完整代码:
/*30ms,0KB*/ #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int d[1001], s[1001]; int main(void) { int m, k, count = 0, oil = 0, temp, maxn = 0; scanf("%d%d", &m, &k); for (int i = 0; i < m; ++i) { scanf("%d", &d[i]); count += d[i]; } for (int i = 0; i < m; ++i) scanf("%d", &s[i]); for (int i = 0; i < m; ++i) { oil += s[i]; maxn = max(maxn, s[i]); if (d[i] > oil) { temp = ceil((double)(d[i] - oil) / maxn); count += k * temp; oil += maxn * temp; } oil -= d[i]; } printf("%d", count); return 0; }
相关文章推荐
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心
- 【Codeforces Round 169 (Div 2) D】【简单数位贪心】Little Girl and Maximum XOR 区间选两数使得异或值尽可能大
- Codeforces Round #334 (Div. 2)C. Alternative Thinking(贪心)
- 【Codeforces Round 274 (Div 2)C】【贪心】Exams a[i]位置写a[i]或b[i] 所有位置的数保证不下降的最早结束时间
- Codeforces Aim Tech Round 3 (Div.2 )C.Letters Cyclic Shift 【贪心】水题
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
- Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪心、数学)
- coderforce Educational Codeforces Round 10 C. Foe Pairs(贪心)
- Codeforces Round #276 (Div. 1)D(贪心+dp)
- codeforces round 345 div2 Image Interview 贪心 + 二分
- Educational Codeforces Round 21 C. Tea Party 贪心
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- Educational Codeforces Round 6 C. Pearls in a Row(贪心)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心+优先队列
- Codeforces Beta Round #69 (Div. 1 Only) C. Beavermuncher-0xFF 树上贪心
- Codeforces Round #199 (Div. 2) B. Xenia and Spies(贪心)
- Educational Codeforces Round 7(E)贪心,思维
- Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation (贪心)
- Codeforces Round #265 (Div. 2) C 暴力+ 找规律+ 贪心
- Codeforces Round #192 (Div. 1) A. Purification(贪心模拟+清除每行每列)