JZOJ 3736. 【NOI2014模拟7.11】数学题
\(\text{Problem}\)
给出向量 \(\boldsymbol a = (x1,y1), \boldsymbol b = (x2,y2)\)
求 \(|\lambda_1\boldsymbol a + \lambda_2\boldsymbol b|\) 的最小值
其中 \(\lambda_1,\lambda_2\) 为整数
\(\text{Solution}\)
二维欧几里得算法的应用
然而并不懂是什么东西,我们只考虑这道题
做法见金斌的集训队论文《欧几里得算法的应用》
Here
注意共线的向量答案为 \(0\) 要特判
\(\text{Code}\)
#include <cstdio>
#include <cmath>
#include <iostream>
#define IN inline
using namespace std;
struct Vector{double x, y;}a, b;
IN double operator * (const Vector &a, const Vector &b){return a.x * b.x + a.y * b.y;}
IN Vector operator * (const Vector &a, double k){return Vector{a.x * k, a.y * k};}
IN Vector operator + (const Vector &a, const Vector &b){return Vector{a.x + b.x, a.y + b.y};}
IN Vector operator - (const Vector &a, const Vector &b){return Vector{a.x - b.x, a.y - b.y};}
IN double cos(Vector a, Vector b){return a * b / (sqrt(a * a) * sqrt(b * b));}
int main()
{
freopen("math.in", "r", stdin), freopen("math.out", "w", stdout);
while (~scanf("%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y))
{
if (a * a > b * b) swap(a, b);
if (a * b < 0) b = b * -1;
double cos_alpha = cos(a, b);
if (cos_alpha >= 1){printf("0\n"); continue;}
while (cos_alpha > 0.5)
{
Vector c = b * cos_alpha;
if (c * c < a * a) b = b - a;
else b = b - a * (int)(sqrt(c * c) / sqrt(a * a));
if (a * a > b * b) swap(a, b);
if (a * b < 0) b = b * -1;
cos_alpha = cos(a, b);
}
printf("%.0lf\n", min(a * a, b * b));
}
}
JZOJ 3736. 【NOI2014模拟7.11】数学题的更多相关文章
- JZOJ 5773. 【NOIP2008模拟】简单数学题
5773. [NOIP2008模拟]简单数学题 (File IO): input:math.in output:math.out Time Limits: 1000 ms Memory Limits ...
- JZOJ【NOIP2013模拟联考14】隐藏指令
JZOJ[NOIP2013模拟联考14]隐藏指令 题目 Description 在d维欧几里得空间中,指令是一个长度为2N的串.串的每一个元素为d个正交基的方向及反方向之一.例如,d = 1时(数轴) ...
- JZOJ.5258【NOIP2017模拟8.11】友好数对
Description
- JZOJ.5257【NOIP2017模拟8.11】小X的佛光
Description
- [JZOJ 4307] [NOIP2015模拟11.3晚] 喝喝喝 解题报告
题目链接: http://172.16.0.132/senior/#main/show/4307 题目: 解题报告: 题目询问我们没出现坏对的连续区间个数 我们考虑从左到有枚举右端点$r$,判断$a[ ...
- JZOJ 4611. 【NOI2016模拟7.11】接水问题 (贪心+A*+可持久化线段树)
Description: https://gmoj.net/senior/#main/show/4611 题解: 先把A从大到小排序,最小的由排序不等式显然. 考虑类似第k短路的A*的做法. 定义状态 ...
- [转载]如何在C++03中模拟C++11的右值引用std::move特性
本文摘自: http://adamcavendish.is-programmer.com/posts/38190.htm 引言 众所周知,C++11 的新特性中有一个非常重要的特性,那就是 rvalu ...
- 「考试」noip模拟9,11,13
9.1 辣鸡 可以把答案分成 每个矩形内部连线 和 矩形之间的连线 两部分 前半部分即为\(2(w-1)(h-1)\),后半部分可以模拟求(就是讨论四种相邻的情况) 如果\(n^2\)选择暴力模拟是有 ...
- ZOJ 3780 - Paint the Grid Again - [模拟][第11届浙江省赛E题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Time Limit: 2 Seconds Me ...
- [jzoj 5664] [GDOI2018Day1模拟4.6] 凫趋雀跃 解题报告(容斥原理)
interlinkage: https://jzoj.net/senior/#contest/show/2703/3 description: solution: 考虑容斥原理,枚举不合法的走的步数 ...
随机推荐
- jquery 操作样式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- .NET 6 基于IDistributedCache实现Redis与MemoryCache的缓存帮助类
本文通过IDistributedCache的接口方法,实现Redis与MemoryCache统一帮助类.只需要在配置文件中简单的配置一下,就可以实现Redis与MemoryCache的切换. 目录 I ...
- whistle证书过期或不信任
1. 安卓设备 , whistle抓包https安装证书后无法访问网络,报证书过期或不信任 2. 查看证书日期是到2030年,没有过期 3. 删除证书 重新安装时候证书选择 "VPN或应用& ...
- 7-3 停车场管理 (20point(s))
设有一个可以停放n辆汽车的狭长停车场,它只有一个大门可以供车辆进出.车辆按到达停车场时间的先后次序依次从停车场最里面向大门口处停放 (即最先到达的第一辆车停放在停车场的最里面) .如果停车场已放满n辆 ...
- pycharm全局搜索
方法有:1.使用[Ctrl+N]快捷键按文件名搜索py文件: 2.使用[Ctrl+shift+N]快捷键按文件名搜索所有类型的文件: 3.使用[ctrl+shift+f]快捷全局字符串搜索: 3.使用 ...
- js获取当前年月日时分
function GetDate(){ var now = new Date(); var year = now.getFullYear(); //年 var month = now.getMonth ...
- IdentityServer4 - v4.x .Net中的实践应用
认证授权服务的创建 以下内容以密码授权方式为例. 创建模拟访问DB各数据源类 为模拟测试准备的数据源. /// 假设的用户模型 public class TestUser { public strin ...
- elasticsearch之单请求多查询
一.需要解决的问题 有的时候我们需要同时执行多个查询,并且需要得到每个单独查询的搜索结果,elasticsearch提供了multi search此需求的支持: 二.elasticsearch mul ...
- day08-AOP-01
AOP 1.官方文档 AOP讲解:下载的spring文件-->spring-framework-5.3.8/docs/reference/html/core.html#aop AOP APIs: ...
- 第一个C程序
写C代码 创建工作区 创建工程 创建文件(.c源文件..h头文件) main函数是程序执行的入口,有且只有一个 函数printf(print function打印函数)[库函数-C语言本身提供给我们使 ...