noip模拟赛 #3
T1
给一个环,每个点有一个权值,把环分成三段,求最小的那段的最大值
sol:暴力
二分答案,chk就是把环搞成三倍链,每次枚举起点,后面三个切割点都可以二分找
然后就Rua过去了
//yyc wenle
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = ;
inline LL read()
{
int x = ,f = ;char ch = getchar();
for(;!isdigit(ch);ch = getchar())if(ch == '-')f = -f;
for(;isdigit(ch);ch = getchar())x = * x + ch - '';
return x * f;
}
int n;
LL s[ * maxn],a[ * maxn];
LL l,r;
inline LL findnx(int pos,LL x){return upper_bound(s,s + * n + ,s[pos] + x - ) - s;}
inline int chk(LL x)
{
int pos;
for(int i=;i<n;i++)
{
pos = i;
pos = findnx(pos,x);if(pos > i + n)continue;
pos = findnx(pos,x);if(pos > i + n)continue;
pos = findnx(pos,x);if(pos > i + n)continue;
return ;
}
return ;
}
int main()
{
n = read();
for(int i=;i<=n;i++){a[i] = read();a[n + i] = a[i];a[ * n + i] = a[i];}
for(int i=;i<= * n;i++)s[i] = s[i - ] + a[i];
l = ,r = s[n] / ;LL ans;
while(l <= r)
{
LL mid = (l + r) >> ;
if(chk(mid))l = mid + ,ans = mid;
else r = mid - ;
}
printf("%lld\n",ans);
}
/*
30
1
34
44
13
30
1
9
3
7
7
20
12
2
44
6
9
44
31
17
20
33
18
48
23
19
31
24
50
43
15
*/
T2
树上选出k个点,如果选一个点,也要选他的祖先,默认选0,每个人有一个战斗力和一个花费
求选出的最大战斗力除以最大花费
sol:
分数规划,每个点权变成了zdl - mid * hf
然后就是“树上选出若干点点权大于0”
然后,我们就想歪了
考虑选出的肯定是很多条链,树上选出很多链?那岂不是...
九省联考_林可卡特树
然后想了半天带权二分...咳咳
然后就去想T3了
写完T3才发现这tm不是个树背包吗
然后算算复杂度
小数点后3位,最大10000,那就是1e8
log1e8 * O(n^2)显然挂了
所以需要一个常数小的写法
考虑dfs序,我们选一个点,可以转移到他dfs序后一个点
不选一个点,就转出这棵子树
然后常数非常的优秀,不需要“证明复杂度”和size写法
(学弟预处理size然后T了
//yyc wenle
#include<bits/stdc++.h>
#define LL long long
#define DB long double
using namespace std;
const int maxn = ;
const double inf = 1e9;
inline int read()
{
int x = ,f = ;char ch = getchar();
for(;!isdigit(ch);ch = getchar())if(ch == '-')f = -f;
for(;isdigit(ch);ch = getchar())x = * x + ch - '';
return x * f;
}
int n,k;
double s[maxn],p[maxn];
int first[maxn],to[maxn],nx[maxn],cnt;
int dfin[maxn],pos[maxn],dfout[maxn],dfn;
double f[][];int ccnt = ;
inline void add(int u,int v)
{
to[++cnt] = v;
nx[cnt] = first[u];
first[u] = cnt;
}
inline void dfs(int x)
{
dfin[x] = ++dfn;
pos[dfn] = x;
for(int i=first[x];i;i=nx[i])dfs(to[i]);
dfout[dfin[x]] = dfn;
}
inline int chk(double x)
{
for(int i=;i<=n + ;i++)
for(int j=;j<=k + ;j++)
f[i][j] = -inf;
f[][] = ;
for(int i=;i<=n+;i++)
for(int j=;j<=k+;j++)
{
if(f[i][j] == -inf)continue;
double cur = p[pos[i]] - x * (s[pos[i]]);
f[dfout[i] + ][j] = max(f[dfout[i] + ][j],f[i][j]);
f[dfout[i] + ][j + ] = max(f[dfout[i] + ][j + ],f[i][j] + cur);
for(int xx=first[pos[i]];xx;xx = nx[xx])
{
int targ = to[xx];
f[dfin[targ]][j + ] = max(f[dfin[targ]][j + ],f[i][j] + cur);
//ccnt++;
}
}
return f[n + ][k + ] >= 0.0;
}
const double eps = 1e-;
int main()
{
//freopen("rantree.in","r",stdin);
//freopen("1.txt","r",stdin);
//freopen("gen.out","w",stdout);
//freopen("mactree.in","r",stdin);
//freopen("chain.in","r",stdin);
//freopen("juhua.in","r",stdin);
k = read(),n = read();
if(!k){puts("0.000");return ;}
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&s[i],&p[i]);int py = read();
add(py,i);
}
dfs();
//cout<<pos[1];
double l = ,r = 10000.0;
for(int tms = ;tms <= ;tms++)
{
if(r - l <= eps)break;
double mid = (l + r) / 2.0;
if(chk(mid))l = mid + eps;
else r = mid - eps;
}
//cout<<ccnt<<endl;
printf("%.3lf",(l + r) / 2.0);
}
T3
给n个门,每个门是一个位运算和一个数,经过这个门就对这个数操作
求1~m经过这些门之后最大的数
sol:
贪心
1.如果这位选0,改了之后变成1,血赚
2.如果这位选1,改了之后变成0,血亏
3.剩下的,选0肯定比选1更小于m
//yyc wenle
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = ;
inline int read()
{
int x = ,f = ;char ch = getchar();
for(;!isdigit(ch);ch = getchar())if(ch == '-')f = -f;
for(;isdigit(ch);ch = getchar())x = * x + ch - '';
return x * f;
}
int n,m;
char opt[];
int num;
int main()
{
n = read(),m = read();
int x = ( << ) - ,y = ;
for(int i=;i<=n;i++)
{
scanf("%s",opt);num = read();
if(opt[] == 'A')x &= num,y &= num;
if(opt[] == 'X')x ^= num,y ^= num;
if(opt[] == 'O')x |= num,y |= num;
}
int a = ,b = ;
for(int i = ( << );i;i >>= )
{
if((a | i) <= m && (x & i) > (y & i))b |= (x & i),a |= i;
else b |= (y & i);
}
printf("%d\n",b);
}
AK了
noip模拟赛 #3的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
随机推荐
- Github上好的Android开源框架
1.volley 项目地址 https://github.com/smanikandan14/Volley-demo (1) JSON,图像等的异步下载: (2) 网络请求的排序(scheduli ...
- springMVC的注释集合
SpringMVC的工作原理 主要核心实现是DispatcherServlet. 一般来讲客户端对服务器发送请求,是由DispatcherServlet控制的,DispatcherServlet接受到 ...
- sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
- maven-tomcat7;IOC;AOP;数据库远程连接
[说明]真的是好烦下载插件啊,maven-tomcat7 插件试了好多次都不行,下载不成:部署不成:好不容易从github中得到的springmvc项目也是运行不起来,中间又是查了许多东西,绕着绕着都 ...
- Js格式化json字符串
var formatJson = function(json, options) { var reg = null, formatted = '', pad = 0, PADDING = ' '; / ...
- Tensorflow 初级教程(二)
一.Tensorflow 扩展功能 1.自动求导 2.子图的执行 3.计算图控制流 4.队列/容器 Tensorflow 自动求导 当计算tensor C关于tensor W的梯度时,会先寻找从W到C ...
- xpath中如何使用变量
xpath (python)xpath中如何使用变量描述: 在xpath中该如何使用变量,想选择id是某个值的元素,这个值是个变量. response.xpath('//div[@id=val]'). ...
- eclipse revert resources 很慢的解决办法
eclipse启动无响应,停留在Loading workbench状态,或老是加载不了revert resources 做开发的同学们或多或少的都会遇到eclipse启动到一定程度时,就进入灰色无响应 ...
- let和var以及const有什么区别
在JavaScript中有三种声明变量的方式:var.let.const. var:声明全局变量,换句话理解就是,声明在for循环中的变量,跳出for循环同样可以使用. for(var i=0;i&l ...
- 动态添加select的option
动态给select标签添加option,结合前人经验以及自己经验,现在总结三种方法供大家参考,一起交流学习! 首先是定义的select元素: //根据ID获得select元素var mySelect ...