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 模 ...
随机推荐
- AngularJS form $addControl 注冊控件control
需求背景: 在form中使用编写的某component directive时.想通过form's name来对form中控件进行操作, 如使用$invalid等来ng-disabled btn. 解决 ...
- 【BZOJ3661】Hungry Rabbit 贪心
[BZOJ3661]Hungry Rabbit Description 可怕的洪水在夏天不期而至,兔子王国遭遇了前所未有的饥荒,它们不得不去外面的森林里寻找食物.为了简化起见,我们假设兔子王国中有n只 ...
- 【BZOJ1778】[Usaco2010 Hol]Dotp 驱逐猪猡 期望DP+高斯消元
[BZOJ1778][Usaco2010 Hol]Dotp 驱逐猪猡 Description 奶牛们建立了一个随机化的臭气炸弹来驱逐猪猡.猪猡的文明包含1到N (2 <= N <= 300 ...
- WIn10远程:mstsc:出现身份验证错误,要求的函数不支持, 这可能是由于CredSSP加密Oracle修正
a.单击 开始 > 运行,输入 regedit,单击 确定. b.定位到 HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Syst ...
- POJ3094 Sky Code(莫比乌斯反演)
POJ3094 Sky Code(莫比乌斯反演) Sky Code 题意 给你\(n\le 10^5\)个数,这些数\(\le 10^5\),问这些这些数组成的互不相同的无序四元组(a,b,c,d)使 ...
- Jquery实现loading效果
需要引入jquery和bootstrap相关包,然后把下面的代码复制进去就可以了: <div class="modal fade" id="loadingModal ...
- You are using pip version 8.1.2, however version 9.0.1 is available.
[root@localhost ~]# pip install virtualenvmapperCollecting virtualenvmapper Could not find a versio ...
- 3.06课·········C#语言基础
Main函数: static void Main(string [] args){ }程序代码需要写在Main函数的花括号内. 一.输出:Console.WriteLine("这是我的第一个 ...
- js实现select动态添加option
关于 select 的添加 option 应该注意的问题. 标准的做法如上也就是说,标准的做法是 s.options.add();但是如果你一定要用 s.appendChild(option);注意了 ...
- MD5加密“破解”在.NET平台实现最基本的理解
MD5作为一种散列算法,广泛用于密码传输过程中的“加密”(引号的意思是这并不是真正的加密,而是形成密码的散列值)过程.MD顾名思义Message Digest(报文摘要),可以将输入的密码,一般来说为 ...