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 贪心二分不知道什么玩意儿反正不会写就对了. 我是个智障
随机推荐
- VS Code设置成中文界面
1.打开VS Code,按:ctrl+shift+p打开指令面板,输入lang,选择Configure Display Language 2.将"locale"后面的"e ...
- J Press the Button
BaoBao and DreamGrid are playing a game using a strange button. This button is attached to an LED li ...
- input 设置 width:100% 和padding后宽度超出父节点
input 设置 width:100% 和padding后宽度超出父节点 添加如下css即可: box-sizing: border-box; -webkit-box-sizing: border-b ...
- 线程同步-使用ReaderWriterLockSlim类
使用ReaderWriterLockSlim创建一个线程安全的机制,在多线程中对一个集合进行读写操作.ReaderWriterLockSlim代表了一个管理资源访问的锁,允许多个线程同时读取,以及独占 ...
- MAC OS X&Vmware
推出共享文件恢复解决办法: 将/Volumes/VMware shared Folders 文件删除(此时这个文件中的内容为乱码) ,生成一个 VMware shared Folders文件夹,重新设 ...
- mybatis BindingException: Invalid bound statement (not found)
错误截图 解决措施 此异常的原因是由于mapper接口编译后在同一个目录下没有找到mapper映射文件而出现的. 通常我们在配置SqlSessionFactory时会有如配置 <!-- 配置Sq ...
- java框架之SpringBoot(7)-异常处理
前言 在 SpringBoot 项目中,默认情况下,使用浏览器访问一个不存在的地址会返回如下错误页面: 而当客户端未非浏览器时,错误信息则会以 json 数据返回,如下: 会出现如上效果的原因是 Sp ...
- [js]js栈内存的全局/私有作用域,代码预解释
js代码如何执行的 浏览器提供执行环境: 全局作用域(提供js执行环境, 栈内存) --> 执行js需要预解释 - 带var : 提前声明 - 带function关键字的: 提前声明+定义 js ...
- DOIS 2019 DevOps国际峰会北京站来袭~
DevOps 国际峰会是国内唯一的国际性 DevOps 技术峰会,由 OSCAR 联盟指导.DevOps 时代社区与高效运维社区联合主办,共邀全球80余名顶级专家畅谈 DevOps 体系与方法.过程与 ...
- typescript 01 认识ts和ts的类型
看ITYING ts专辑(前三集总结) TypeScript 是 Javascript 的超级,遵循最新的 ES6.Es5 规范.TypeScript 扩展了 JavaScript 的语法.TypeS ...