UESTC 1047 Alice's birthday
2016-06-07 21:22
579 查看
原题地址:http://acm.uestc.edu.cn/#/problem/show/1047
题意
一条长为n的路,Bob要从一个端点走到另一个端点,途中有m个服务站,每个服务站提供两种服务可供选择
1.瞬间向前前进一个单位的距离
2.使Bob走过一个距离的要花的时间减1
问Bob在每个服务站如何选择可以使自己最快到达路的另一端。
题解
对于方案二,永远是晚选不如早选
所以贪心就好
枚举选择方案二的次数
决策问题:贪心 or DP
题意
一条长为n的路,Bob要从一个端点走到另一个端点,途中有m个服务站,每个服务站提供两种服务可供选择
1.瞬间向前前进一个单位的距离
2.使Bob走过一个距离的要花的时间减1
问Bob在每个服务站如何选择可以使自己最快到达路的另一端。
题解
对于方案二,永远是晚选不如早选
所以贪心就好
枚举选择方案二的次数
决策问题:贪心 or DP
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int maxn=1e5; int dist[maxn+5]; LL T[maxn+5]; int main(void) { #ifdef ex freopen ("in.txt","r",stdin); //freopen ("out.txt","w",stdout); #endif LL n,m,t; scanf("%lld%lld%lld",&n,&m,&t); for (int i=1;i<=m;++i) { scanf("%d",&dist[i]); } T[0]=0; LL ans=t*(n-m); for (int i=1;i<=m;++i) { T[i]=T[i-1]+t*(dist[i]-dist[i-1]); ans=min(ans,T[i]+(t-1)*(n-dist[i]-(m-i))); --t; if (t==0) break; } printf("%lld\n",ans); }
相关文章推荐
- 拾遗系列(一)之UIView
- iOS UISearchController Class Reference
- 一些基础的控件
- 96. Unique Binary Search Trees
- EasyUI datagrid在Layout中动态适应问题
- Adafruit公司2015年最棒的开源可穿戴设备
- GCD之dispatch queue深入浅出
- 云计算--在bluemix平台上部署一个JavaWeb程序
- POJ 1141 Brackets Sequence 区间dp
- Codeforces #353 (div2)A. Infinite Sequence
- BZOJ 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
- iOS setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key 问题
- View requires API level 14 (current min is 8): <GridLayout>的解决方法-
- 用Mockplus教你使用属性面板的设置交互状态
- UISearchController Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
- 用任务管理器关闭客户端后,服务器的早先投递的WSARecv没有从GetQueuedCompletionStatus返回
- iOS开发UI基础—手写控件,frame,center和bounds属性
- UIBezierPath + CAShapeLayer的简单使用
- ndk错误解决方法 ndk-build NDK_PROJECT_PATH
- iOS UIButton实现上显示图片,下显示文字