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发生的啥事儿都说下吧~ 嗯,我是一个比较沙茶的人,不过运气比较好吧. 高中啊,这个谈起来话就长了,在校什么风采之星大赛上,我认识了个妹子,当时感觉 ...
随机推荐
- 树--四分树(UVa297)
郑重声明: 数据结构这部分内容, 由于博主才学很少(且很浅)的内容, 所以现在所写的(大都是抄的)一些典型例题, 再加上一些自己想法和理解而已, 等博主勤加修炼, 以后会大有补充和改进. 粗浅之处, ...
- 《FLASH CC 2015 CANVAS 中文教程》——2、基本的交互(点击、触摸)事件
注::如果你对 FLASH 这个软件操作不够熟悉,建议你可以先看看FLASH动画之类的书. :FLASH CC 在文中直接简称为CC. :以下所以文章中所说的快捷键 如果你按了不起作用,请检查是否有其 ...
- MVC加载下拉列表
public ActionResult GetList() { string strSql = "select staff_id,nick_name from tbl_ac_info whe ...
- FTP常用故障代码注解
FTP错误列表 出处:http://bbs.enet.com.cn/UserControl?act=13&threadID 作者: |秒杀』| 详细的FTP错误列表 Restart marke ...
- win10系统更新补丁时进度条一直卡在0%不动的解决方案
为了能够让win10系统更加安全稳定,很多用户都会时不时为自己的电脑安装补丁.不过,部分用户在为win10系统更新补丁时,却会遇到进度条一直卡在0%不动的问题.这该怎么办呢?下面,小编就告诉大家解决该 ...
- Myeclipse 主题下载
Myeclipse 主题下载 下载网址: 1. 编辑区背景主题:http://www.eclipsecolorthemes.org 2. 框架主题:https://marketplace.eclips ...
- ORACLE 总结
1. diagnostic file(alertlog, tracefile, redolog), 监控数据库动作时间点 [troubleshooting] alertlog : 确认checkpoi ...
- maven setting.xml配置说明
文件存放位置 全局配置: ${M2_HOME}/conf/settings.xml 用户配置: ${user.home}/.m2/settings.xml note:用户配置优先于全局配置.${use ...
- Android Context 是什么?
andorid 开发(42) 版权声明:本文为博主原创文章,未经博主允许不得转载. [转载请注明出处:http://blog.csdn.net/feiduclear_up CSDN 废墟的树] PS ...
- 【linux命令】:查看当前登录用户的信息,本文介绍3种方法
作为系统管理员,你可能经常会(在某个时候)需要查看系统中有哪些用户正在活动.有些时候,你甚至需要知道他(她)们正在做什么.本文为我们总结了4种查看系统用户信息(通过编号(ID))的方法. 1. 使用w ...