[乱搞] BZOJ 1484 [HNOI2009]通往城堡之路
来源:互联网 发布:cr2怎么转换成jpg mac 编辑:程序博客网 时间:2024/04/30 13:56
什么仙人掌DP啊,我好怕怕啊
题解:http://blog.csdn.net/zeyu_king/article/details/44924517
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; } return *p1++;} inline void read(ll &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;} const int N=5005; ll n,d,ans; ll a[N],b[N]; int main(){freopen("t.in","r",stdin);freopen("t.out","w",stdout); ll Q,s,delta,tmp,minx,x; read(Q); while (Q--) { read(n); read(d); for (int i=1;i<=n;i++) read(a[i]); if (abs(a[n]-a[1])>(ll)(n-1)*d){ printf("impossible\n"); continue; } b[1]=a[1]; for (int i=2;i<=n;i++) b[i]=b[i-1]-d; while (a[n]!=b[n]) { s=0; delta=1<<30; minx=1<<30; tmp=-1<<30; for (int i=n;i>1;i--){ if (a[i]>b[i]) s++,minx=min(minx,a[i]-b[i]); else s--; if (tmp<s && b[i-1]+d>b[i]) tmp=s,x=i,delta=minx; } delta=min(delta,b[x-1]+d-b[x]); for (int i=x;i<=n;i++) b[i]+=delta; } ans=0; for (int i=1;i<=n;i++) ans+=abs(a[i]-b[i]); printf("%lld\n",ans); } return 0; }
0 0
- [乱搞] BZOJ 1484 [HNOI2009]通往城堡之路
- [bzoj 1484] HNOI2009 通往城堡之路
- BZOJ 1484: [HNOI2009]通往城堡之路
- bzoj 1484 [HNOI2009]通往城堡之路 贪心
- bzoj1484: [HNOI2009]通往城堡之路
- luogu P3202 [HNOI2009]通往城堡之路
- hnoi 2009 通往城堡之路
- 通往阿里之路
- 通往大神之路
- 通往java高手之路
- 通往架构师之路
- BZOJ 1483: [HNOI2009]梦幻布丁
- 【BZOJ 1486】 [HNOI2009]最小圈
- BZOJ 1486: [HNOI2009]最小圈
- [BZOJ 1486][HNOI2009]最小圈
- BZOJ 1483: [HNOI2009]梦幻布丁
- BZOJ 1486: [HNOI2009]最小圈
- BZOJ 1487: [HNOI2009]无归岛
- 近期学习javascript和jquery遇到一些问题的技巧知识总结
- Aggregating local descriptors into a compact image representation(阅读)
- I2C子系统驱动架构 - 具体实现
- struts2环境搭建
- 脚本化文档(2)
- [乱搞] BZOJ 1484 [HNOI2009]通往城堡之路
- LeetCode - 75. Sort Colors
- Nginx核心配置深入理解及优化
- Spring注解@Component、@Repository、@Service、@Controller区别
- linux下查找某个文件位置的方法
- CSS3 timing-function: steps() 详解
- codeforces_679B. Bear and Tower of Cubes(贪心+二分+dfs)
- [仙人掌DP] BZOJ 4316 小C的独立集
- Linux里如何查找文件内容