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发生的啥事儿都说下吧~ 嗯,我是一个比较沙茶的人,不过运气比较好吧. 高中啊,这个谈起来话就长了,在校什么风采之星大赛上,我认识了个妹子,当时感觉 ...
随机推荐
- Python基础学习笔记(十)日期Calendar和时间Timer
参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-date-time.html 3. http://www.liao ...
- 面向对象的JavaScript系列二,继承
1.原型链 function SuperType(){ this.property = true; } SuperType.prototype.getSuperValue = function(){ ...
- 个人博客作业_week2
1. 是否需要有代码规范 1.这些规范都是官僚制度下产生的浪费大家的编程时间.影响人们开发效率,浪费时间的东西. 我不同意这个论点. 有句俗语’无规矩不成方圆‘,这亘古传承的至理同样适用 ...
- STRUTS2 常用标签的使用
<body> <h1>s:if标签的用法</h1> <s:set name="price" value="25"> ...
- getAttribute()方法的使用小笔记
今天在某课网上复习js,突然卡在一个小例子上.反复做了几遍就是报错.终于查询w3c才找到错误的源头. 这里记录一下,谨防以后又忘了. 错误码: <body> <p id=" ...
- boost线程的问题:
可以看看这里:http://blog.csdn.net/misskissc/article/details/9859753 我的总结: 1,用thread类来创建一个线程,它的构结函数 : (1)th ...
- 【Todo】LR-逻辑回归
因为逻辑回归对于计算广告学非常重要.也是我们平时广告推荐.CTR预估最常用到的算法.所以单独开一篇文章讨论. 参考这篇文章:http://www.cnblogs.com/sparkwen/p/3441 ...
- ElasticSearch(ES)和solr的关系和区别
可以参考这篇文章:http://www.cnblogs.com/chowmin/articles/4629220.html Solr 2004年诞生(当时是Solar). ElasticSearch ...
- RPC的学习 & gprotobuf 和 thrift的比较
参考 http://blog.csdn.net/pi9nc/article/details/17336663 集成libevent,google protobuf的RPC框架 RPC(Remote P ...
- 树状数组求逆序对:POJ 2299、3067
前几天开始看树状数组了,然后开始找题来刷. 首先是 POJ 2299 Ultra-QuickSort: http://poj.org/problem?id=2299 这题是指给你一个无序序列,只能交换 ...