HDU3401,列完转移方程拆分一下,正着、反着跑优先队列优化代表买或卖。初始化不大会搞……

 #include <bits/stdc++.h>
using namespace std; const int inf = 0x3f3f3f3f;
const int maxn = ;
int T, n, maxp, w;
int ap, bp, as, bs;
int f[maxn][maxn];
int q[maxn], v[maxn]; int DP() {
for (int j = ; j <= maxp; j++)
f[][j] = -inf;
for (int i = ; i <= w+; i++) {
scanf("%d%d%d%d", &ap, &bp, &as, &bs); for (int j = ; j <= maxp; j++) {
if (j <= as) f[i][j] = -j*ap;
else f[i][j] = -inf;
f[i][j] = max(f[i][j], f[i-][j]);
}
}
for (int i = w+; i <= n; i++) {
scanf("%d%d%d%d", &ap, &bp, &as, &bs); int l = , r = ;
for (int j = ; j <= maxp; j++) {
f[i][j] = f[i-][j];
while (l <= r && f[i-w-][j] + j*ap > v[r]) r--;
q[++r] = j;
v[r] = f[i-w-][j] + j*ap; while (l <= r && q[l] < j-as) l++;
if (l <= r) f[i][j] = max(f[i][j], v[l]-j*ap);
} l = , r = ;
for (int j = maxp; ~j; j--) {
while (l <= r && f[i-w-][j] + j*bp > v[r]) r--;
q[++r] = j;
v[r] = f[i-w-][j] + j*bp; while (l <= r && q[l] > j+bs) l++;
if (l <= r) f[i][j] = max(f[i][j], v[l]-j*bp);
}
}
return f[n][];
} int main() {
for (cin >> T; T; T--) {
cin >> n >> maxp >> w;
cout << DP() << endl;
}
return ;
}

为了少一些痛苦自闭,蒟蒻只好写几道cf水题。

 #include <bits/stdc++.h>
using namespace std; int n; int main() {
while (cin >> n) {
int m = n/;
for (int i = m; i; i--)
if (__gcd(i, n-i) == ) {
printf("%d %d\n", i, n-i);
break;
}
}
return ;
}

854A

 #include <bits/stdc++.h>
using namespace std; int n, k; int main() {
while (cin >> n >> k) {
if (k > && k < n)
printf("1 ");
else printf("0 "); printf("%d\n", min(n - k, *k));
}
return ;
}

854B

优先队列乱模拟一下:

 #include <bits/stdc++.h>
using namespace std; typedef pair<int, int> P;
int n, k;
priority_queue<P> Q;
set<int> minute;
set<int>::iterator it;
int v[];
long long ans; int main() {
cin >> n >> k;
for (int i = ; i <= n; i++) {
int cost;
scanf("%d", &cost);
Q.push(P(cost, i));
minute.insert(i+k);
} for (int i = ; i <= n; i++) {
auto t = Q.top(); Q.pop();
int k1 = t.second;
if (k1 < k) k1 = k;
it = minute.lower_bound(k1);
v[t.second] = *it;
ans += (long long)(*it - t.second) * t.first;
minute.erase(it);
} cout << ans << endl;
for (int i = ; i <= n; i++)
printf("%d ", v[i]);
return ;
}

853A

差分预处理,枚举区间:

 #include <bits/stdc++.h>
#define ll long long
#define ri readint()
#define gc getchar()
#define pb push_back
#define P pair<int, int>
using namespace std; const ll INF = 1e13;
const int maxn = ;
const int maxday = ; int n, m, k;
ll f[maxn];
ll s[maxday+], t[maxday+];
vector<int> from[maxday+], to[maxday+], cost[maxday+]; inline int readint() {
int x = , s = , c = gc;
while (c <= ) c = gc;
if (c == '-') s = -, c = gc;
for (; isdigit(c); c = gc)
x = x* + c - ;
return x * s;
} void init(ll *x, int k) {
for (int i = ; i <= n; i++)
f[i] = INF;
x[k] = INF*n;
} int main() {
cin >> n >> m >> k;
for (int i = ; i < m; i++) {
int day = ri, f = ri, t = ri, c = ri;
from[day].pb(f);
to[day].pb(t);
cost[day].pb(c);
} init(s, );
for (int i = ; i <= maxday; i++) {
s[i] = s[i-];
for (int j = ; j < from[i].size(); j++) {
if (to[i][j] == && cost[i][j] < f[from[i][j]]) {
s[i] -= f[from[i][j]] - cost[i][j];
f[from[i][j]] = cost[i][j];
}
}
}
init(t, maxday+);
for (int i = maxday; i; i--) {
t[i] = t[i+];
for (int j = ; j < from[i].size(); j++) {
if (from[i][j] == && cost[i][j] < f[to[i][j]]) {
t[i] -= f[to[i][j]] - cost[i][j];
f[to[i][j]] = cost[i][j];
}
}
} ll ans = INF;
for (int i = ; i + k <= maxday; i++)
ans = min(ans, s[i-] + t[i+k]);
if (ans > 1e12) puts("-1");
else cout << ans << endl; return ;
}

853B

BZOJ1010,斜率优化dp经典题,推式子很重要,设定不同的函数做法也会有难易区分。

 #include <bits/stdc++.h>
#define db double
#define maxn 50005
using namespace std; int n, L;
int head, tail;
int q[maxn];
db sum[maxn], f[maxn]; db sqr(db x) {
return x * x;
}
db a(int i) {//斜率单调的
return sum[i] + i;
}
db b(int i) {
return sum[i] + i + L + ;
}
db Y(int i) {
return f[i] + sqr(b(i));
}
db slope(int i, int j) {
return (Y(j) - Y(i)) / (b(j) - b(i));
} int main() {
cin >> n >> L;
for (int i = ; i <= n; i++) {
scanf("%lf", &sum[i]);
sum[i] += sum[i-];
}
head = , tail = ;
for (int i = ; i <= n; i++) {
while (head < tail && slope(q[head], q[head+]) < *a(i)) head++;
f[i] = f[q[head]] + sqr(a(i) - b(q[head])); while (head < tail && slope(q[tail-], q[tail]) > slope(q[tail-], i)) tail--;
q[++tail] = i;
}
cout << fixed << setprecision() << f[n] << endl;
return ;
}

#10:wannanewtry——6的更多相关文章

  1. Windows 10:解决开机显示C:\WINDOWS\system32\config\systemprofile\Desktop不可用的方法

      开机显示C:\WINDOWS\system32\config\systemprofile\Desktop不可用应该是不少网友都遇到过. 近日在使用Windows 10 Build 9926中,也出 ...

  2. 【译】ASP.NET MVC 5 教程 - 10:添加验证

    原文:[译]ASP.NET MVC 5 教程 - 10:添加验证 在本节中,我们将为Movie模型添加验证逻辑,并确认验证规则在用户试图使用程序创建和编辑电影时有效. DRY 原则 ASP.NET M ...

  3. Bootstrap入门(十六)组件10:well和具有响应式特性的嵌入内容

    Bootstrap入门(十六)组件10:well和具有响应式特性的嵌入内容 well组件可以为内容增添一种切入效果. 具有响应式特性的嵌入内容可以根据被嵌入内容的外部容器的宽度,自动创建一个固定的比例 ...

  4. RTMPdump(libRTMP) 源代码分析 10: 处理各种消息(Message)

    ===================================================== RTMPdump(libRTMP) 源代码分析系列文章: RTMPdump 源代码分析 1: ...

  5. sed:-e 表达式 #1,字符 10:未终止的“s”命令

    执行shell脚本时,使用sed变量替换指定的字符串,一直出现这个错误: [root@bqh-118 scripts]# vim while_rz.sh [root@bqh-118 scripts]# ...

  6. Module 10:I/O流(java如何实现与外界数据的交流)

    Module 10:I/O流(java如何实现与外界数据的交流) Input/Output:指跨越出了JVM的边界,与外界数据的源头或者目标数据源进行数据交换.               输出   ...

  7. Window 10 :我的性能优化:那效果,杠杠的!

    微软的 windows 10,不错! 当全新安装后,性能总觉得别别扭扭,不那么干净利落. 下面就是我的个人优化措施,期间有很多技术性的操作,如果你没有动手能力,或者是技术小白,可以不用再看了! (1) ...

  8. Window 10 :如何彻底关闭:Windows Defender Service(2015-12-20日更新)

    Window 10 :如何彻底关闭:Windows Defender Service? 网上流传的什么组策略gpeidt.msc方法,什么安装其他的杀软之类的方法都很麻烦,且有弊病! 其实很简单: 利 ...

  9. 搞懂分布式技术10:LVS实现负载均衡的原理与实践

    搞懂分布式技术10:LVS实现负载均衡的原理与实践 浅析负载均衡及LVS实现 原创: fireflyc 写程序的康德 2017-09-19 负载均衡 负载均衡(Load Balance,缩写LB)是一 ...

随机推荐

  1. Window 64位下的客户机配置PLSQL链接远程Oracle

    此文章记录的是艰难探索. 完成如下工作: 服务器A为Windows Serve 2016:安装Oracle. 客户机B为Win7 x64位,安装PLSQLDevelop,链接A上的Oracle. 首先 ...

  2. 利用javascript动态创建表格

    //说明:实现功能.原理上文相同.不过这次是利用已有的简单的方法创建行和列,并实现内容行鼠标移入变色功能! 效果图: /*两个方法 1.  trNode  table.insertRow(-1)    ...

  3. jquery之extend

    jquery的extend方法的用法1. [代码][JavaScript]代码     01<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01// ...

  4. 腾讯Hermes设计概要——数据分析用的是列存储,词典文件前缀压缩,倒排文件递增id、变长压缩、依然是跳表-本质是lucene啊

    转自:http://data.qq.com/article?id=817 三.Hermes设计概要 架构描述 系统核心进程均采用分散化设计,根据业务发展需求,可随意扩缩容机器; 周期性数据直接通过td ...

  5. 用css截取字符 css排版隐藏溢出文本

    方法一: <div style="width:300px; overflow:hidden;  text-overflow:ellipsis; white-space:nowrap;& ...

  6. BZOJ2006:超级钢琴(ST表+堆求前K大区间和)

    Description 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为1至n.第i个音符的美妙度 ...

  7. Swift 控制语句

    Control Flow指的是『逻辑控制语句』,包括if.if-else.for.for-in.while.do-while.switch等.其中大部分和OC中差不多,但Swift在某些方便增强了控制 ...

  8. Windows Vista for Developers——第四部分:用户帐号控制(User Account Control,UAC)

    作者:Kenny Kerr 翻译:Dflying Chen 原文:http://weblogs.asp.net/kennykerr/archive/2006/09/29/Windows-Vista-f ...

  9. HDU1083(最大匹配)

    Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  10. git add . 的时候遇到warning: LF will be replaced by CRLF inXXX 解决办法

    $ git add . warning: LF will be replaced by CRLF in shop/Runtime/Cache/86bbc820c9ec1 d314a9c71cf5651 ...