Codeforces Round #298 (Div. 2) B. Covered Path

题目大意:

一辆车,每秒内的速度恒定...第I秒到第I+1秒的速度变化不超过D。初始速度为V1,末速度为V2,经过时间t,问最远能走多远。

分析

开始的时候想麻烦了。讨论了各种情况。后来发现每个时刻的最大值都满足一定的约束关系。设此时为时刻i,上一次的速度为p,那么本次的速度应为max(p+d,v2+(t-i)*d),因为要保证最终一定能够返回到v2。这样以来便可以得到每个时刻的最大值,然后累加求和即可。

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 int main()
 5 {
 6     int v1,v2,t,d;
 7     int a[10000];
 8     while(scanf("%d %d",&v1,&v2)!=EOF)
 9     {
10         scanf("%d %d",&t,&d);
11         a[0]=v1;
12         int k=0,tem=v1;
13         for(int i=2;i<=t;i++)
14         {
15             tem=min(tem+d,v2+(t-i)*d);
16             a[++k]=tem;
17         }
18         int sum=0;
19         for(int i=0;i<=k;i++)
20             sum+=a[i];
21         printf("%d\n",sum);
22     }
23     return 0;
24 }
时间: 2024-08-04 05:35:51

Codeforces Round #298 (Div. 2) B. Covered Path的相关文章

Codeforces Round #298 (Div. 2) A、B、C题

题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side

Codeforces Round #298 (Div. 2)

A - Exam 构造 1 #include <cstdio> 2 3 int ans[5000 + 5]; 4 5 int main() { 6 int n, cnt = 1; 7 scanf("%d", &n); 8 for (int i = 1; i <= n; i++) { 9 if (i&1) ans[i] = cnt; 10 else { 11 ans[i] = n+1-cnt; 12 cnt++; 13 } 14 } 15 ans[0]

Codeforces Round #298 (Div. 2), problem: (A) Exam

A. Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspe

#298 (div.2) B. Covered Path

1.题目描述:点击打开链接 2.解题思路:本题利用贪心法解决.一开始想着利用dfs解决,不过最终意料之中地TLE了,因为每次可以选择的速度增加量有很多,一共2*d个,这样的话,时间复杂度是O(T*D^T)达到了指数级别.所以应当改变思路,想办法求出每个时刻的最大值.通过尝试可以发现,每个时刻的最大值都满足一定的约束关系.设此时为时刻i,上一次的速度为p,那么本次的速度应为max(p+d,v2+(t-i)*d),因为要保证最终一定能够返回到v2.这样以来便可以得到每个时刻的最大值,然后累加求和即可

Codeforces Round #298 (Div. 2) A. Exam(水)

题意:N 个学生 编了号,  然后第i个学生不能和第i+1和第i-1坐在一起,问合法的情况下最多坐多少个人,如何做 题解: 水题YY了一下,打表处理前三种    后面的情况就是在第三种情况下往前后插数字   奇数在后  偶数在前,然后没了 代码: #include<stdio.h> #include<string.h> int main() { int n, mymap[5005]; int mark[3][4] = {{1, 1}, {1, 1}, {2, 1, 3}}; whi

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round 239 Div 1

都怪自己太懒了 这段时间比赛参加了大部分,但是一直都没写题解,趁这几天没事,计划把这段时间的题解都补上. 上一次比赛(248)终于升到了div1,所以从这次开始就开始写div1了. A. Triangle There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such

Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn LCA(最近公共祖先)

C. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. Ther

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities【最短路】

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities[最短路] 题目链接:点击打开 题目大意: 在一个国家中有n个城市(城市编号1~n),m条公路和k条铁路,编号为1的城市为首都,为了节约,不需要的铁路需要关闭,问在保证首都到其余所有城市的最短路不变的条件下,最多有多少条铁路是不需要的. 解法: 这个题比较麻烦,保证首都到其余城市的最短路不变,要求出最多有多少条铁路是不需要的,那肯定是从最短路的代码上下手了,我们首先考虑dijkstra算法