BZOJ3308 九月的咖啡店
Orz PoPoQQQ
话说这题还有要注意的地方。。。
就是。。。不能加SLF优化,千万不能加
n = 40000,不加本机跑出来2sec,加了跑出来40sec。。。【给跪了
/**************************************************************
Problem: 3308
User: rausen
Language: C++
Result: Accepted
Time:27500 ms
Memory:32752 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#include <bitset> using namespace std;
const int N = 2e4 + ;
const int Cnt = N * ;
const int M = Cnt * ;
const int inf = 1e9; struct edges {
int next, to, f, cost;
edges() {}
edges(int _n, int _t, int _f, int _c) : next(_n), to(_t), f(_f), cost(_c) {}
} e[M]; int n, ans, S, T;
int first[N], tot = ;
bitset <Cnt> not_p;
int pr[N], tot_p, tot_a, tot_b;
int d[N], g[N], v[N]; inline void Add_Edges(int x, int y, int f, int c) {
e[++tot] = edges(first[x], y, f, c), first[x] = tot;
e[++tot] = edges(first[y], x, , -c), first[y] = tot;
} inline void calc() {
static int x;
for (x = g[T]; x; x = g[e[x ^ ].to])
--e[x].f, ++e[x ^ ].f;
} #define y e[x].to
inline bool spfa() {
static int x, now, q[];
static unsigned short l, r;
for (x = ; x <= T; ++x)
d[x] = -inf;
d[S] = , v[S] = , q[] = S;
for(l = r = ; l != r + ; ) {
now = q[l++];
for (x = first[now]; x; x = e[x].next) {
if (e[x].f && d[now] + e[x].cost > d[y]) {
d[y] = d[now] + e[x].cost, g[y] = x;
if (!v[y])
v[y] = , q[++r] = y;
}
}
v[now] = ;
}
return d[T] >= ;
}
#undef y inline int work() {
int res = ;
while (spfa())
calc(), res += d[T];
return res;
} void get_prime(int N) {
int i, j, k;
for (i = ; i <= n; ++i) {
if (!not_p[i]) pr[++tot_p] = i;
for (j = ; j <= tot_p; ++j) {
if ((k = i * pr[j]) > N) break;
not_p[k] = ;
if (i % pr[j] == ) break;
}
}
} inline int get(int n, int p) {
static int res;
for (res = ; res * p <= n; res *= p);
return res;
} int main() {
int i, j, tmp;
scanf("%d", &n);
get_prime(n);
for (i = ; i <= tot_p && 1ll * pr[i] * pr[i] <= n; ++i) ++tot_a;
for (; i <= tot_p && pr[i] * <= n; ++i) ++tot_b;
for (; i <= tot_p; ++i) ans += pr[i];
S = tot_a + tot_b + , T = S + ; #define J j + tot_a
for (i = ; i <= tot_a; ++i)
Add_Edges(S, i, , ), Add_Edges(i, T, , get(n, pr[i]));
for (j = ; j <= tot_b; ++j)
Add_Edges(S, J, , pr[J]), Add_Edges(J, T, , );
for (i = ; i <= tot_a; ++i)
for (j = ; j <= tot_b; ++j)
if ((tmp = get(n / pr[J], pr[i]) * pr[J]) > get(n, pr[i]) + pr[J])
Add_Edges(i, J, , tmp);
#undef J
printf("%d\n", ans + + work());
return ;
}
(p.s. 成功成为最慢的2333)
BZOJ3308 九月的咖啡店的更多相关文章
- [bzoj3308]九月的咖啡店_欧拉筛素数_费用流
bzoj-3308 九月的咖啡店 题目大意:深绘里在九份开了一家咖啡让,如何调配咖啡民了她每天的头等大事我们假设她有N种原料,第i种原料编号为i,调配一杯咖啡则需要在这里若干种兑在一起.不过有些原料不 ...
- 【BZOJ-3308】九月的咖啡店 最大费用最大流 + 线性筛素数
3308: 九月的咖啡店 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 159 Solved: 56[Submit][Status][Discuss ...
- 【BZOJ 3308】 3308: 九月的咖啡店 (费用流|二分图最大权匹配)
3308: 九月的咖啡店 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 244 Solved: 86 Description 深绘里在九份开了一家咖 ...
- bzoj 3308: 九月的咖啡店【最大费用最大流】
费用流里spfa最后的判断要写成dis[t]>=0而不是dis[t]!=-inf否则会WAWAWA-- #include<iostream> #include<cstdio&g ...
- bzoj 3308 九月的咖啡店
题目大意: 求若干个<=n的数 两两互质 使和最大 求这个最大的和 思路: 显然,得到两个结论 1 最终的所有数都只能分解为两个质因数 2 这两个质因数 一个<根号n 一个>根号n ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 九月 26, 2017 10:18:14 上午 com.sun.jersey.server.impl.application.RootResourceUriRules <init> 严重: The ResourceConfig instance does not contain any root resource classes.
Tomcat启动错误:九月 26, 2017 10:18:14 上午 com.sun.jersey.server.impl.application.RootResourceUriRules <i ...
- IT女孩特不烦恼---九月实习总结
对着岁月落笔,画出一场清风,那是最真的笑容 一溜烟的功夫,小编来实习Android已经四个月了,从刚开始的电商项目到现在的车段子项目,小编渐渐对这个曾经陌生的名字慢慢扭转变成熟悉的面孔,四个月的时间, ...
- 九月回顾 这篇文章和ACM毫无关系= =
其实不只是九月的回顾吧,我大概想把暑假到现在10.01发生的啥事儿都说下吧~ 嗯,我是一个比较沙茶的人,不过运气比较好吧. 高中啊,这个谈起来话就长了,在校什么风采之星大赛上,我认识了个妹子,当时感觉 ...
随机推荐
- VS生成事件
源自:http://www.cnblogs.com/FreeDong/p/3406737.html 如果说磨刀不误砍柴工,同样用好Visual Studio,会大大增加咱.NET程序猿效率.本文说的就 ...
- ubuntu下配置hosts
由于Chrome浏览器访问问题,需要配置hosts. 在Ubuntu系统下,需要修改/etc/hosts文件,修改完之后要重启网络.具体过程如下:1.修改hostssudo vi /etc/hosts ...
- SQL SERVER分区表
简介 分区表是在SQL SERVER2005之后的版本引入的特性.这个特性允许把逻辑上的一个表在物理上分为很多部分.而对于SQL SERVER2005之前版本,所谓的分区表仅仅是分布式视图,也就是多个 ...
- 期权交易基本原理——买进看跌期权(Long Put),卖出看跌期权(Short Put)
期权交易基本原理--买进看跌期权(Long Put),卖出看跌期权(Short Put) 来源:中电投先融期货-青岛 浏览:13508次2014-07-25 14:25:55 3 第三节 买进看跌期权 ...
- jquery使用技巧
1. 禁用右键点击(Disable right-click) <!DOCTYPE html> <html> <head> <meta charset=&quo ...
- linux学习笔记2-命令总结3
文件搜索命令 1.文件搜索命令 find 2.其他文件搜索命令 grep - 在文件中搜索字串匹配的行并输出 locate - 在文件资料库中查找文件 whereis - 搜索命令所在目录及帮助文档路 ...
- Java 多线程 (转)
http://www.ibm.com/developerworks/cn/java/j-thread/index.html http://www.ibm.com/developerworks/cn/j ...
- linux终端下 编译c语言程序
linux终端下,编译C语言程序步骤为: 采用vi进行源代码编写,编写完成后,:wq存盘退出,如: vi test.c 在命令行下,运行gcc编译程序,生成执行码,如: gcc -o test te ...
- UIButton的常见设置
- (void)setTitle:(NSString *)title forState:(UIControlState)state;设置按钮的文字 - (void)setTitleColor:(UIC ...
- TextView使用SpannableString设置复合文本
TextView通常用来显示普通文本,但是有时候需要对其中某些文本进行样式.事件方面的设置.Android系统通过SpannableString类来对指定文本进行相关处理,具体有以下功能: 1.Bac ...