题目大意:

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

分析

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

 #include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int v1,v2,t,d;
int a[];
while(scanf("%d %d",&v1,&v2)!=EOF)
{
scanf("%d %d",&t,&d);
a[]=v1;
int k=,tem=v1;
for(int i=;i<=t;i++)
{
tem=min(tem+d,v2+(t-i)*d);
a[++k]=tem;
}
int sum=;
for(int i=;i<=k;i++)
sum+=a[i];
printf("%d\n",sum);
}
return ;
}

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

  1. Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举

    B. Covered Path Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...

  2. 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 nar ...

  3. CodeForces Round #298 Div.2

    A. Exam 果然,并没有3分钟秒掉水题的能力,=_=|| n <= 4的时候特判.n >= 5的时候将奇数和偶数分开输出即可保证相邻的两数不处在相邻的位置. #include < ...

  4. Codeforces Round #298 (Div. 2)A B C D

    A. Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  5. Codeforces Round #298 (Div. 2) E. Berland Local Positioning System 构造

    E. Berland Local Positioning System Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.c ...

  6. Codeforces Round #298 (Div. 2) D. Handshakes 构造

    D. Handshakes Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem ...

  7. Codeforces Round #298 (Div. 2) C. Polycarpus' Dice 数学

    C. Polycarpus' Dice Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/p ...

  8. Codeforces Round #298 (Div. 2) A. Exam 构造

    A. Exam Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/A Des ...

  9. Codeforces Round #298 (Div. 2)--D. Handshakes

    #include <stdio.h> #include <algorithm> #include <set> using namespace std; #defin ...

随机推荐

  1. ruby学习网站

    Ruby官方中文网(推荐): https://www.ruby-lang.org/zh_cn/ 国内非常不错的Ruby学习教程网站(推荐): http://www.yiibai.com/ruby Ru ...

  2. python 爬虫

    import urllib2 as url import re urls = 'http://www.php100.com/html/it/' headers = {'User-Agent':'Moz ...

  3. js获取浏览器的版本代码

    <script>function GetXmlHttpObject(){var xmlHttp=null;var httptype='';try { // Firefox, Opera 8 ...

  4. UVa 11762 - Race to 1

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  5. Hibernate 通过 Session 操纵对象

    Session 概述 •Session 接口是 Hibernate 向应用程序提供的操纵数据库的最主要的接口, 它提供了基本的保存, 更新, 删除和加载 Java 对象的方法. •Session 具有 ...

  6. C++-高效的swap

    原始版本: template<typename T> void swap(T& a, T& b) { T tmp(a); a = b; b = tmp; } 此版本不重视效 ...

  7. ASP.NET 学习笔记

    1.ASP.NET 服务器控件是可被服务器理解的标签 有三种类型的服务器控件(所有服务器控件必须出现在 <form> 标签内,同时 <form> 标签必须包含 runat=&q ...

  8. 升级Xcode6.4插件失效解决办法

    发现安装的插件无效 后各种尝试后终于解决 1.先找到之前装的插件文件夹 前往文件夹:~/Library/Application Support/Developer/Shared/Xcode/Plug- ...

  9. [vijos P1023] Victoria的舞会3

    这… 本来想学习一下Tarjan算法的,没想到码都码好了发现这题不是求强连通分量而是简单的连通分量…图论基础都还给老师了啊啊啊!最后深搜通通解决! v标记是否被访问过,scc标记每个的祖先(本来想写T ...

  10. eclipse web项目实际工程路径对应

    src/1.properties ---->实际路径 /WEB-INF/classes/1.propertiessrc/com.ayong.one/2.properties /WEB-INF/c ...