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 模 ...
随机推荐
- 请求SQL数据是存在<null>,的解决方法
删除字典中的null 我们在处理服务器传过来的数据过程中,如果数据中出现null,我们是没法进行本地持久化处理的.在使用NSUserDaults保存本地时,如果其中一个字段的value为NULL值,就 ...
- poj2075
Tangled in Cables Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6348 Accepted: 2505 ...
- POJ 286 Y2K Accounting Bug【简单暴力】
链接: http://poj.org/problem?id=2586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#probl ...
- iOS基础动画的KeyPath取值
一 .基础动画 1.基础动画的属性详解 注:Core Animation的动画执行过程都是在后台操作的,不会阻塞主线程. 属性 解读 Autoreverses 设定这个属性为 YES 时,在它到达目的 ...
- 【python】-- pymsql 操作MySQL
pymysql 对MySQL数据库进行简单数据操作python模块主要是:MySQLdb.pymsql,MySQLdb模块主要用于python2.X,而python3.X则使用pymsql,pymys ...
- mydql练习答案
.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 思路: 获取所有有生物课程的人(学号,成绩) - 临时表 获取所有有物理课程的人(学号,成绩) - 临时表 根据[学号]连接两个临时表: 学号 ...
- Unity 武器拖尾效果
Pocket RPG Weapon Trails 武器拖尾效果 Asset Store地址:https://www.assetstore.unity3d.com/en/#!/content/2458 ...
- matlab + c/c++ opencv 混合编程
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...
- Arduino 看门狗使用
1.需要调用 #include <avr/wdt.h> 2.设置看门狗复位时间 wdt_enable(WDTO_2S); 代码时间定义的底层查看 #define WDTO_15MS 0 / ...
- 每天一个Linux命令(35)wc命令
Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. (1)用法: 用法: wc [选项] [文件]. ...