2018.9.22 NOIP模拟赛
*注意:这套题目应版权方要求,不得公示题面。
因为业务水平下滑太严重,去和高一考NOIP模拟,sad。。。
Problem A 妹子
题目大意
给定两个矩形,问一个能否将一个矩形放在另一个矩形里面。
先可以根据面积判断哪一个被放在里面,然后判断一下能不能直接放或者旋转90°放进去。
如果不行的话,接着考虑旋转。我们考虑这样↓放置小矩形。

连接$EG$,作$GI\perp AD$于点$I$,$FJ\perp AD$与点$D$,$GK\perp JF$于点$G$。
考虑上下界$AB$和$CD$和左界$AD$的限制,暂时放开$BC$的限制,然后我们考虑最小化$GI$。
因为$GI^{2} = GE^2 - IE^2$,$GE$是定值,所以最小化$IG$等价于最大化$IE$。
易证四边形$JKGI$是矩形,所以$JI = KG$。易证$\angle FGK=\angle JFE=\angle DEH $。
再由$EH = FG,\angle EDH = \angle FKG = 90^{\circ}$,可得$\triangle EDH \cong \triangle GKF$。
所以$JI = KG = ED$当$E$点向下移动的时候$DI$增大,$JI,ED$减小,所以当$DJ = AD$时,$IG$有最小值。
为了满足IG最小,我们这样放置矩形↓

设$AF = x, \frac{EF}{EH} = k, w_{1} = EF, w_{2} = AD$。
因为$\left\{\begin{matrix}\angle AFE = \angle DEH\ \ \ \ \ \ \ \ \ \ \\\angle EAF = \angle EDH = 90^{\circ} \end{matrix}\right.$,所以$\triangle AFE \sim \triangle DEH$、
所以$ED = \frac{x}{k}, AE = \sqrt{w_{1}^{2} - x^{2}}$,然后有$k \cdot w_{2} - x = k\sqrt{w_{1}^{2} - x^{2}}$。
然后有:
$\left\{ \begin{matrix} k^{2} \cdot w_{2}^2 - 2x\cdot k\cdot w_{2} + x^2 = k^2w_{1}^{2} - k^2x^{2} \\ 0< x \leqslant w_{1}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \\ k \cdot w_{2} - x > 0\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \end{matrix} \right.$
解一下,判断是否满足$CD$限制就行了。1
Code
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
typedef bool boolean;
int T;
int w1, h1, w2, h2;
double w;
inline void init() {
scanf("%d%d%d%d", &w1, &h1, &w2, &h2);
if (w1 * h1 > w2 * h2) {
swap(w1, w2);
swap(h1, h2);
}
}
boolean checkRoot(double x) {
|| x > w1)
return false;
double k = w1 * 1.0 / h1;
double y = sqrt(w1 * w1 - x * x);
return x + y / k <= h2;
}
boolean check() {
double k = w1 * 1.0 / h1;
;
* k * w2;
double c = k * (w1 * w1 - w2 * w2);
* a * c;
)
return false;
double qd = sqrt(delta);
* a), x2 = (-b + qd) / ( * a);
return checkRoot(x1) || checkRoot(x2);
}
namespace old {
boolean check() {
if (w1 <= w2 && h1 <= h2)
return true;
if (w1 >= w2 && h1 >= h2)
return true;
return false;
}
inline boolean solve() {
if (check()) {
puts("Yes");
return true;
}
swap(h1, w1);
if (check()) {
puts("Yes");
return true;
}
swap(h1, w1);
swap(h2, w2);
if (check()) {
puts("Yes");
return true;
}
return false;
}
}
inline void solve() {
if (old::solve())
return;
if (check())
puts("Yes");
else {
swap(h1, w1);
if (check())
puts("Yes");
else
puts("No");
}
}
int main() {
scanf("%d", &T);
while (T--) {
init();
solve();
}
;
}
Problem A
Problem B 旅程
题目大意
给定$n$个点的带权有向完全图。要求支持删除一条边以及询问两点之间的最短路。
$1\leqslant n\leqslant 200, 1\leqslant m\leqslant 10^5$,删除操作不超过$200$次。
没有插入,倒着做,变成加。
然后考虑这条边带来的贡献,枚举一对点,用它来更新最短路。
时间复杂度$O(n^3 + m)$
Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
typedef bool boolean;
;
);
typedef class Operation {
public:
int type;
int x, y;
int data;
Operation() { }
Operation(int type, int x, int y):type(type), x(x), y(y) { }
}Operation;
int n, m;
int d[N][N];
int f[N][N];
Operation *os;
inline void init() {
scanf("%d%d", &n, &m);
; i <= n; i++)
; j <= n; j++)
scanf("%d", d[i] + j);
os = )];
, op, x, y; i <= m; i++) {
scanf("%d%d%d", &op, &x, &y);
os[i] = Operation(op, x, y);
) {
os[i].data = d[x][y];
d[x][y] = inf;
}
}
}
inline void solve() {
memcpy(f, d, sizeof(f));
; i <= n; i++)
f[i][i] = ;
; k <= n; k++)
; i <= n; i++)
if (i ^ k)
; j <= n; j++)
if ((j ^ k) && (j ^ i))
f[i][j] = min(f[i][k] + f[k][j], f[i][j]);
for (int i = m; i; i--) {
int op = os[i].type, x = os[i].x, y = os[i].y;
) {
int data = os[i].data;
if (data != inf) {
; u <= n; u++)
; v <= n; v++)
if (u ^ v)
f[u][v] = min(f[u][x] + data + f[y][v], f[u][v]);
}
} else {
if (f[x][y] == inf)
os[i].data = -;
else
os[i].data = f[x][y];
}
}
; i <= m; i++)
)
printf("%d\n", os[i].data);
}
int main() {
// freopen("journey.in", "r", stdin);
// freopen("journey.out", "w", stdout);
init();
solve();
;
}
Problem B
Problem C 老大
题目大意
要求在树上找两个点,然后其他所有点到它们两个点的距离的最小值的最大值最小。
Solution 1 Binary search
二分答案$mid$,从最后一个点向上跳$mid$个点作为第一个选定点,然后把它的势力范围内的点都删掉,然后对剩下的点做一次,再判断是否有点剩余。
时间复杂度$O(n\log n)$
Solution 2 Dynamic programming
考虑只选一个点的时候,答案是最长链长度除以二向上取整。(根据最长链定义然后用反证法)。
选两个点就相当于每个点有个势力范围,分界边将树分成一个比较好看的子树,以及它的补。正反各一次求树上最长链dp就完了。
Code
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <ctime>
using namespace std;
typedef bool boolean;
typedef class Data {
public:
int mxlen;
int mxdep;
Data():mxlen(), mxdep() { };
Data(int mxlen, int mxdep):mxlen(mxlen), mxdep(mxdep) { }
Data operator + (Data b) {
Data rt;
rt.mxlen = max(mxlen, max(b.mxlen, b.mxdep + mxdep));
rt.mxdep = max(mxdep, b.mxdep);
return rt;
}
Data trans() {
);
}
}Data;
;
vector<int> *g;
vector<int> *ts;
Data *fu, *fd;
Data *top;
Data *pool;
Data* alloc(int size) {
Data* rt = top;
top = top + size;
return rt;
}
inline void init() {
scanf("%d", &n);
fu = )];
fd = )];
pool = ) + ];
g = )];
ts = )];
top = pool;
, u, v; i < n; i++) {
scanf("%d%d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
// cerr << clock() << endl;
}
void dp1(int p, int fa) {
Data& f = fu[p];
; i < (signed) g[p].size(); i++) {
int e = g[p][i];
if (e == fa)
continue;
ts[p].push_back(e);
dp1(e, p);
f = f + fu[e].trans();
}
}
void dp2(int p) {
Data f = fd[p].trans() + Data(, );
)
f = Data(, );
int s = (signed) ts[p].size();
Data* pred = alloc(s + );
Data* sufd = alloc(s + );
Data d(, );
; i < s; i++) {
int e = ts[p][i];
d = d + fu[e].trans();
pred[i] = d;
}
d = Data(, );
; ~i; i--) {
int e = ts[p][i];
d = d + fu[e].trans();
sufd[i] = d;
}
; i < s; i++) {
int e = ts[p][i];
fd[e] = f;
if (i)
fd[e] = fd[e] + pred[i - ];
)
fd[e] = fd[e] + sufd[i + ];
dp2(e);
}
}
int ceil2(int x) {
) >> ;
}
inline void solve() {
dp1(, );
dp2();
; i <= n; i++)
res = min(res, max(ceil2(fd[i].mxlen), ceil2(fu[i].mxlen)));
)
res = ;
printf("%d\n", res);
}
int main() {
// freopen("ob.in", "r", stdin);
// freopen("ob.out", "w", stdout);
init();
solve();
;
}
Problem C
2018.9.22 NOIP模拟赛的更多相关文章
- 2018.10.16 NOIP模拟赛解题报告
心路历程 预计得分:\(100 + 100 + 20 = 220\) 实际得分:\(100 + 100 + 30 = 230\) 辣鸡模拟赛.. T1T2都是一眼题,T3考验卡常数还只有一档暴力分. ...
- 2018.08.22 NOIP模拟 string(模拟)
string [描述] 给定两个字符串 s,t,其中 s 只包含小写字母以及*,t 只包含小写字母. 你可以进行任意多次操作,每次选择 s 中的一个*,将它修改为任意多个(可以是 0 个)它的前一个字 ...
- 2018.02.12 noip模拟赛T2
二兵的赌注 Description游戏中,二兵要进入了一家奇怪的赌场.赌场中有n个庄家,每个庄家都可以猜大猜小,猜一次一元钱.每一次开彩前,你都可以到任意个庄家那里下赌注.如果开彩结果是大,你就可以得 ...
- 2018.9.25 NOIP模拟赛
*注意:这套题目应版权方要求,不得公示题面. 从这里开始 Problem A XOR Problem B GCD Problem C SEG 表示十分怀疑出题人水平,C题数据和标程都是错的.有原题,差 ...
- EZ 2018 07 06 NOIP模拟赛
又是慈溪那边给的题目,这次终于没有像上次那样尴尬了, T1拿到了较高的暴力分,T2没写炸,然后T3写了一个优雅的暴力就203pts,Rank3了. 听说其它学校的分数普遍100+,那我们学校还不是强到 ...
- 2018.08.22 NOIP模拟 shop(lower_bound+前缀和预处理)
Shop 有 n 种物品,第 i 种物品的价格为 vi,每天最多购买 xi 个. 有 m 天,第 i 天你有 wi 的钱,你会不停购买能买得起的最贵的物品.你需要求出你每天会购买多少个物品. [输入格 ...
- 2018.08.22 NOIP模拟 or(线段树)
or [描述] 构造一个长度为 n 的非负整数序列 x,满足 m 个条件,第 i 个条件为x[li] | x[li+1] | - | x[ri]=pi. [输入] 第一行两个整数 n,m.接下来 m ...
- 2018/3/20 noip模拟赛 5分
T1 傻逼题,写了cmp没sort,5分. T2 树上差分,写了树剖线段树,超时,0分. T3 树归,0分. 我是个zz
- 2018/3/18 noip模拟赛 20分
T1 dp,特别裸特别简单,我放弃了写了个dfs. T2 树归,特别裸特别简单,我不会写. T3 贪心二分不知道什么玩意儿反正不会写就对了. 我是个智障
随机推荐
- 理解vue之element-ui中的 <template slot-scope="scope">
https://blog.csdn.net/tg928600774/article/details/81945140?utm_source=blogxgwz1
- 算法提高 最小方差生成树(Kruskal)_模板
算法提高 最小方差生成树 时间限制:1.0s 内存限制:256.0MB 问题描述 给定带权无向图,求出一颗方差最小的生成树. 输入格式 输入多组测试数据.第一行为N,M,依次是 ...
- Dalvik虚拟机执行流程图
- Vue.js中滚动条加载更多数据
本文章参考:http://www.cnblogs.com/ssrsblogs/p/6108423.html 分析:1.需要判断滚动条是否到底部: 需要用到DOM的三个属性值,即scrollTop.cl ...
- thinkphp5中使用PHPExcel(转载)
thinkphp5中可以使用composer来获取第三方类库,使用起来特别方便,例如:可是使用composer下载PHPMailer,think-captcha(验证码)等等…… 接下来说一下怎么使用 ...
- div左右居中css
l_btn{ font-size: 1.2rem; width: 190px; height: 50px; border: 1px solid #fff; border-radius: 25px; c ...
- 静态方法(staticmethod)和类方法(classmethod)
类方法:有个默认参数cls,并且可以直接用类名去调用,可以与类属性交互(也就是可以使用类属性) 静态方法:让类里的方法直接被类调用,就像正常调用函数一样 类方法和静态方法的相同点:都可以直接被类调用, ...
- 剑指offer——python【第14题】链表中倒数第k个节点
题目描述 输入一个链表,输出该链表中倒数第k个结点. 思路 注意,看清楚,是输出节点,而不是输出节点值 可以先求出链表总长度,然后正向遍历得到第n个节点 解答 class Solution: def ...
- org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password:
tationProcessor' to allow for resolving potential circular referencesDEBUG 2018-05-28 11:32:35,016 o ...
- oracle索引分类
参考文档:https://wenku.baidu.com/view/d4d6ee1ba76e58fafab00336.html https://blog.csdn.net/u010719917/art ...