当前位置: 首页 > news >正文

CSP-J 2023 T3 一元二次方程 解题报告

CSP-J 2023 T3 一元二次方程 解题报告

Link

前言

今年 C S P CSP CSP的原题, 回家 1 h 1h 1h内写 A C AC AC, 但是考场上没有写出来 , 原因是脑子太不好了, 竟然调了两个小时没有调出来. 一等奖悬那…

正题

看完题目,第一眼就是大模拟, 并且 C C F CCF CCF绝对不会让你好受,所以出了一个如此刁钻的题目, 并且要考虑到非常多的情况, 代码非常长…

最重要的一点: Δ \Delta Δ

Δ \Delta Δ是此题中最重要的分情况讨论的地方. 根据初三 22 22 22章的所学知识 ,可知分三种情况:

1. Δ < 0 \Delta < 0 Δ<0

不用说了
直接输出NO

2. Δ = 0 \Delta = 0 Δ=0

同样的, 只有一种情况, 答案为 − b 2 a - \dfrac{b}{2a} 2ab,但是, 需要严谨的判断.

if(delta == 0) {if(b == 0) {cout << 0;}else if(a * b > 0) {a = abs(a);b = abs(b);cout << "-";if(b % (2 * a) == 0) {cout << b / 2 / a;}else {cout << b / __gcd(2 * a, b) << "/" << (2 * a) / __gcd(2 * a, b);}}else {a = abs(a);b = abs(b);if(b % (2 * a) == 0) {cout << b / 2 / a;}else {cout << b / __gcd(2 * a, b) << "/" << (2 * a) / __gcd(2 * a, b);}}
}

3. Δ > 0 \Delta > 0 Δ>0

地狱.
我是分两种情况的, 一种是 a > 0 a > 0 a>0, 一种是 a < 0 a < 0 a<0. 这样可以分辨出是 + Δ + \sqrt{\Delta } +Δ 还是 − Δ -\sqrt{\Delta } Δ

如若 a < 0 a < 0 a<0, 则可知答案为:
b + Δ − 2 a \dfrac{b + \sqrt{\Delta}}{-2a} 2ab+Δ

如若 a > 0 a > 0 a>0, 则可知答案为:
Δ − b 2 a \dfrac{\sqrt{\Delta} - b}{2a} 2aΔ b

  • 在这里有一个技巧, 就是不论怎样, 输出时, Δ \sqrt{\Delta} Δ 永远是正的(符号为+)

可以分两种情况:
1.第一种: 不需要写sqrt, 也就是 Δ \Delta Δ完全平方数时,

比较好处理, 首先需要判断 b + Δ b + \sqrt{\Delta} b+Δ 是否为 0 0 0. 如果是, 则直接输出 0 0 0; 否则输出最简分数.

其中, 一定要记住如果 ( b + Δ ) % ( 2 ∗ a ) = 0 (b + \sqrt{\Delta}) \% (2 * a) = 0 (b+Δ )%(2a)=0, 就直接输出一个整数.还要注意判断正负号.

2.第二种: 需要写sqrt, 很难.

首先, 先输出前面的内容, 也就是 − b 2 a -\dfrac{b}{2a} 2ab, 判断同上.

然后, 输出+, 代表符号.

接着, 找出三个变量, 也就是: x y Δ x 2 \dfrac{x}{y} \sqrt{\dfrac{\Delta}{x^2}} yxx2Δ 中的 x , y 和 Δ x 2 x, y和\dfrac{\Delta}{x^2} x,yx2Δ.其中, Δ x 2 \sqrt{\dfrac{\Delta}{x^2}} x2Δ 为最简平方根数.

接下来是 4 4 4种情况:

x = y x = y x=y, 只有 Δ x 2 \sqrt{\dfrac{\Delta}{x^2}} x2Δ ;

x % y = 0 x \% y = 0 x%y=0, 只有 x y Δ x 2 \dfrac{x}{y}\sqrt{\dfrac{\Delta}{x^2}} yxx2Δ

y % x = 0 y \% x = 0 y%x=0, 只有 Δ x 2 y \dfrac{\sqrt{\dfrac{\Delta}{x^2}}}{y} yx2Δ

其他情况, 输出 x × Δ x 2 y \dfrac{x \times \sqrt{\dfrac{\Delta}{x^2}}}{y} yx×x2Δ

完结撒花!!

C o d e : Code: Code:

  • 心脏病患者请勿观看
#include <bits/stdc++.h>
using namespace std;int T, M;
int a, b, c;int pd(int x) {for(int i = sqrt(x) + 1; i >= 1; --i) {if(x % (i * i) == 0) {return i;}}
}int main() {cin >> T >> M;while(T--) {cin >> a >> b >> c;int delta;delta = b * b - 4 * a * c;if(delta < 0) {cout << "NO";}else if(delta == 0) {if(b == 0) {cout << 0;}else if(a * b > 0) {a = abs(a);b = abs(b);cout << "-";if(b % (2 * a) == 0) {cout << b / 2 / a;}else {cout << b / __gcd(2 * a, b) << "/" << (2 * a) / __gcd(2 * a, b);}}else {a = abs(a);b = abs(b);if(b % (2 * a) == 0) {cout << b / 2 / a;}else {cout << b / __gcd(2 * a, b) << "/" << (2 * a) / __gcd(2 * a, b);}}}else {if(a < 0) {int mother = - 2 * a;int x = pd(delta);int y = delta / x / x;if(b == 0) {mother = abs(mother);if(y == 1) {if(x == mother) {cout << "1";}else if(x % mother == 0) {cout << x / mother;}else {cout << x / __gcd(x, mother) << "/" << mother / __gcd(x, mother);}}else {if(x == mother) {cout << "sqrt(" << y << ")";}else if(mother % x == 0) {cout << "sqrt(" << y << ")";cout << "/" << mother / x;}else if(x % mother == 0) {cout << x / mother << "*sqrt(" << y << ")";}else {cout << x / __gcd(x, mother) << "*sqrt(" << y << ")" << "/" << mother / __gcd(x, mother);}}}else if(y == 1) { // 不需要sqrt// 说明可以合并为同一个式子int son = - b - x;if(son == 0) {cout << 0;}else if(son * mother < 0) { // 如果分子分母同号.son = abs(son);mother = abs(mother);if(son % mother == 0) {cout << son / mother;}else {cout << son / __gcd(son, mother) << "/" << mother / __gcd(son, mother);}}else { // 如果分子分母异号.son = abs(son);mother = abs(mother);cout << "-";if(son % mother == 0) {cout << son / mother;}else {cout << son / __gcd(son, mother) << "/" << mother / __gcd(son, mother);}}}else { // 需要sqrt.// 1. 先输出前面的if(b > 0) { // 不需要负号b = abs(b);mother = abs(mother);if(b % mother == 0) {cout << b / mother;}else {cout << b / __gcd(b, mother) << "/" << mother / __gcd(b, mother);}}else { // 需要负号b = abs(b);mother = abs(mother);cout << "-";if(b % mother == 0) {cout << b / mother;}else {cout << b / __gcd(b, mother) << "/" << mother / __gcd(b, mother);}}// 2. 输出sqrt部分(不管怎样都是+)cout << "+";if(x == 1) { // 不需要输出前缀.cout << "sqrt(" << y << ")";cout << "/" << - 2 * a;}else {if(x == mother) {cout << "sqrt(" << y << ")";}else if(x % mother == 0) {cout << x / mother << "*sqrt(" << y << ")";}else if(mother % x == 0) {cout << "sqrt(" << y << ")";cout << "/" << mother / x;}else {cout << x / __gcd(x, mother);cout << "*sqrt(" << y << ")";cout << "/" << mother / __gcd(x, mother);}}}}else {int mother = 2 * a;int x = pd(delta);int y = delta / x / x;if(b == 0) {mother = abs(mother);if(y == 1) {if(x == mother) {cout << "1";}else if(x % mother == 0) {cout << x / mother;}else {cout << x / __gcd(x, mother) << "/" << mother / __gcd(x, mother);}}else {if(x == mother) {cout << "sqrt(" << y << ")";}else if(mother % x == 0) {cout << "sqrt(" << y << ")";cout << "/" << mother / x;}else if(x % mother == 0) {cout << x / mother << "*sqrt(" << y << ")";}else {cout << x / __gcd(x, mother) << "*sqrt(" << y << ")" << "/" << mother / __gcd(x, mother);}}}else if(y == 1) { // 不需要sqrt// 说明可以合并为同一个式子int son = - b + x;if(son == 0) {cout << 0;}else if(son * mother > 0) { // 如果分子分母同号.son = abs(son);mother = abs(mother);if(son % mother == 0) {cout << son / mother;}else {cout << son / __gcd(son, mother) << "/" << mother / __gcd(son, mother);}}else { // 如果分子分母异号.son = abs(son);mother = abs(mother);cout << "-";if(son % mother == 0) {cout << son / mother;}else {cout << son / __gcd(son, mother) << "/" << mother / __gcd(son, mother);}}}else { // 需要sqrt.// 1. 先输出前面的if(b * mother < 0) { // 不需要负号b = abs(b);mother = abs(mother);if(b % mother == 0) {cout << b / mother;}else {cout << b / __gcd(b, mother) << "/" << mother / __gcd(b, mother);}}else { // 需要负号b = abs(b);mother = abs(mother);cout << "-";if(b % mother == 0) {cout << b / mother;}else {cout << b / __gcd(b, mother) << "/" << mother / __gcd(b, mother);}}// 2. 输出sqrt部分(不管怎样都是+)cout << "+";if(x == 1) { // 不需要输出前缀.cout << "sqrt(" << y << ")";cout << "/" << 2 * a;}else {mother = 2 * a;if(x == mother) {cout << "sqrt(" << y << ")";}else if(x % mother == 0) {cout << x / mother << "*sqrt(" << y << ")";}else if(mother % x == 0) {cout << "sqrt(" << y << ")";cout << "/" << mother / x;}else {cout << x / __gcd(x, mother);cout << "*sqrt(" << y << ")";cout << "/" << mother / __gcd(x, mother);}}}}}cout << endl;}return 0;
}

相关文章:

CSP-J 2023 T3 一元二次方程 解题报告

CSP-J 2023 T3 一元二次方程 解题报告 Link 前言 今年 C S P CSP CSP的原题, 回家 1 h 1h 1h内写 A C AC AC, 但是考场上没有写出来 , 原因是脑子太不好了, 竟然调了两个小时没有调出来. 一等奖悬那… 正题 看完题目,第一眼就是大模拟, 并且 C C F CCF CCF绝对不会让你好受…...

中颖单片机SH367309全套量产PCM,专用动力电池保护板开发资料

方案总体介绍 整套方案硬件部分共2块板子&#xff0c;包括MCU主板&#xff0c;采用SH79F6441-32作为主处理器。MCU主板包括2个版本。PCM动力电池保护板采用SH367309。 软件方案采用Keil51建立的工程&#xff0c;带蓝牙的版本&#xff0c;支持5~16S电池。 硬件方案--MCU主板 MC…...

Android数据对象序列化原理与应用

序列化与反序列化 序列化是将对象转换为可以存储或传输的格式的过程。在计算机科学中&#xff0c;对象通常是指内存中的数据结构&#xff0c;如数组、列表、字典等。通过序列化&#xff0c;可以将这些对象转换为字节流或文本格式&#xff0c;以便在不同的系统之间进行传输或存…...

Linux cp命令:复制文件和目录

cp 命令&#xff0c;主要用来复制文件和目录&#xff0c;同时借助某些选项&#xff0c;还可以实现复制整个目录&#xff0c;以及比对两文件的新旧而予以升级等功能。 cp 命令的基本格式如下&#xff1a; [rootlocalhost ~]# cp [选项] 源文件 目标文件 选项&#xff1a; -a&…...

SpringBoot 接收不到 post 请求数据与接收 post 请求数据

文章归档&#xff1a;https://www.yuque.com/u27599042/coding_star/xwrknb7qyhqgdt10 SpringBoot 接收不到 post 请求数据 接收 post 请求数据&#xff0c;控制器方法参数需要使用 RequestParam 注解修饰 public BaseResponseResult<Object> getMailCode(RequestParam…...

vue3学习(十四)--- vue3中css新特性

文章目录 样式穿透:deep()scoped的原理 插槽选择器:slotted()全局选择器:global()动态绑定CSScss module 样式穿透:deep() 主要是用于修改很多vue常用的组件库&#xff08;element, vant, AntDesigin&#xff09;&#xff0c;虽然配好了样式但是还是需要更改其他的样式就需要用…...

Python爬虫基础之Requests详解

目录 1. 简介2. 安装3. 发送请求4. 处理响应5. IP代理6. Cookie登录参考文献 原文地址&#xff1a;https://program-park.top/2023/10/27/reptile_4/ 本文章中所有内容仅供学习交流使用&#xff0c;不用于其他任何目的&#xff0c;严禁用于商业用途和非法用途&#xff0c;否则由…...

C++求根节点到叶子节点数字之和

文章目录 题目链接题目描述解题思路代码复杂度分析 题目链接 LCR 049. 求根节点到叶节点数字之和 - 力扣&#xff08;LeetCode&#xff09; 题目描述 给定一个二叉树的根节点 root &#xff0c;树中每个节点都存放有一个 0 到 9 之间的数字。 每条从根节点到叶节点的路径都代表…...

C++搜索二叉树

本章主要是二叉树的进阶部分&#xff0c;学习搜索二叉树可以更好理解后面的map和set的特性。 1.二叉搜索树概念 二叉搜索树的递归定义为&#xff1a;非空左子树所有元素都小于根节点的值&#xff0c;非空右子树所有元素都大于根节点的值&#xff0c;而左右子树也是二叉搜索树…...

软件工程17-18期末试卷

2.敏捷开发提倡一个迭代80%以上的时间都在编程&#xff0c;几乎没有设计阶段。敏捷方法可以说是一种无计划性和纪律性的方法。错 敏捷开发是一种软件开发方法论&#xff0c;它强调快速响应变化、持续交付有价值的软件、紧密合作和适应性。虽然敏捷方法鼓励迭代开发和灵活性&…...

课题学习(九)----阅读《导向钻井工具姿态动态测量的自适应滤波方法》论文笔记

一、 引言 引言直接从原论文复制&#xff0c;大概看一下论文的关键点&#xff1a; 垂直导向钻井工具在近钻头振动和工具旋转的钻井工作状态下&#xff0c;工具姿态参数的动态测量精度不高。为此&#xff0c;通过理论分析和数值仿真&#xff0c;提出了转速补偿的算法以消除工具旋…...

阿里云服务器—ECS快速入门

这里对标阿里云的课程&#xff0c;一步步学习&#xff0c;链接在下面&#xff0c;学习完考试及格即可获取阿里云开发认证和领取证书&#xff0c;大家可以看看这个&#xff0c;这里我当作笔记&#xff0c;记一下提升印象&#xff01; 内容很长&#xff0c;请耐心看完&#xff0…...

Hive简介及核心概念

本专栏案例数据集链接: https://download.csdn.net/download/shangjg03/88478038 1.简介 Hive 是一个构建在 Hadoop 之上的数据仓库,它可以将结构化的数据文件映射成表,并提供类 SQL 查询功能,用于查询的 SQL 语句会被转化为 MapReduce 作业,然后提交到 Hadoop 上运行。 …...

CrossOver 23.6.0 虚拟机新功能介绍

CrossOver 23.6.0 Mac 此应用程序允许您运行为 Microsoft Windows 编写的程序&#xff0c;而无需实际安装操作系统。 CrossOver 23.6.0 Mac 包括一个 Windows 程序库&#xff0c;用于它可以运行的 Windows 程序。 您会发现非常流行的应用程序&#xff0c;例如 Microsoft Word…...

(免费领源码)Java#Springboot#mysql农产品销售管理系统47627-计算机毕业设计项目选题推荐

摘 要 随着互联网趋势的到来&#xff0c;各行各业都在考虑利用互联网将自己推广出去&#xff0c;最好方式就是建立自己的互联网系统&#xff0c;并对其进行维护和管理。在现实运用中&#xff0c;应用软件的工作规则和开发步骤&#xff0c;采用Java技术建设农产品销售管理系统。…...

centos更改yum源

1、更改yum源 阿里云/etc/yum.repos.d/CentOS-Base.repo 金山云/etc/yum.repos.d/cloud.repo vi /etc/yum.repos.d/cloud.repo 替换为 [base] nameCentOS-$releasever - Base mirrorlisthttp://mirrorlist.centos.org/?release$releasever&arch$basearch&repoos&…...

React-快速搭建开发环境

1.安装 说明&#xff1a;react-excise-01是创建的文件名 npx create-react-app react-excise-01 2. 打开文件 说明:we suggest that you begin by typing:下面即是步骤。 cd react-excise-01 npm start 3.显示...

算法随想录算法训练营第四十六天| 583. 两个字符串的删除操作 72. 编辑距离

583. 两个字符串的删除操作 题目&#xff1a;给定两个单词 word1 和 word2 &#xff0c;返回使得 word1 和 word2 相同所需的最小步数。 每步 可以删除任意一个字符串中的一个字符。 思路&#xff1a;这题思路主要是求出 word1 字符串和 word2 字符串中的最长相同的子字符串&…...

vue源码分析(五)——vue render 函数的使用

文章目录 前言一、render函数1、render函数是什么&#xff1f; 二、render 源码分析1.执行initRender方法2.vm._c 和 vm.$createElement 调用 createElement 方法详解&#xff08;1&#xff09;区别&#xff08;2&#xff09;代码 3、原型上的_render方法&#xff08;1&#xf…...

Maven第三章:IDEA集成与常见问题

Maven第三章:IDEA集成与常见问题 前言 本章内容重点:了解如何将Maven集成到IDE(如IntelliJ IDEA或Eclipse)中,以及使用过程中遇到的常见的问题、如何解决,如何避免等,可以大大提高开发效率。 IEAD导入Maven项目 File ->Open 选择上一章创建的Maven项目 my-app查看po…...

【OSG学习笔记】Day 18: 碰撞检测与物理交互

物理引擎&#xff08;Physics Engine&#xff09; 物理引擎 是一种通过计算机模拟物理规律&#xff08;如力学、碰撞、重力、流体动力学等&#xff09;的软件工具或库。 它的核心目标是在虚拟环境中逼真地模拟物体的运动和交互&#xff0c;广泛应用于 游戏开发、动画制作、虚…...

cf2117E

原题链接&#xff1a;https://codeforces.com/contest/2117/problem/E 题目背景&#xff1a; 给定两个数组a,b&#xff0c;可以执行多次以下操作&#xff1a;选择 i (1 < i < n - 1)&#xff0c;并设置 或&#xff0c;也可以在执行上述操作前执行一次删除任意 和 。求…...

Unit 1 深度强化学习简介

Deep RL Course ——Unit 1 Introduction 从理论和实践层面深入学习深度强化学习。学会使用知名的深度强化学习库&#xff0c;例如 Stable Baselines3、RL Baselines3 Zoo、Sample Factory 和 CleanRL。在独特的环境中训练智能体&#xff0c;比如 SnowballFight、Huggy the Do…...

Java线上CPU飙高问题排查全指南

一、引言 在Java应用的线上运行环境中&#xff0c;CPU飙高是一个常见且棘手的性能问题。当系统出现CPU飙高时&#xff0c;通常会导致应用响应缓慢&#xff0c;甚至服务不可用&#xff0c;严重影响用户体验和业务运行。因此&#xff0c;掌握一套科学有效的CPU飙高问题排查方法&…...

Netty从入门到进阶(二)

二、Netty入门 1. 概述 1.1 Netty是什么 Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. Netty是一个异步的、基于事件驱动的网络应用框架&#xff0c;用于…...

Chromium 136 编译指南 Windows篇:depot_tools 配置与源码获取(二)

引言 工欲善其事&#xff0c;必先利其器。在完成了 Visual Studio 2022 和 Windows SDK 的安装后&#xff0c;我们即将接触到 Chromium 开发生态中最核心的工具——depot_tools。这个由 Google 精心打造的工具集&#xff0c;就像是连接开发者与 Chromium 庞大代码库的智能桥梁…...

HubSpot推出与ChatGPT的深度集成引发兴奋与担忧

上周三&#xff0c;HubSpot宣布已构建与ChatGPT的深度集成&#xff0c;这一消息在HubSpot用户和营销技术观察者中引发了极大的兴奋&#xff0c;但同时也存在一些关于数据安全的担忧。 许多网络声音声称&#xff0c;这对SaaS应用程序和人工智能而言是一场范式转变。 但向任何技…...

Cilium动手实验室: 精通之旅---13.Cilium LoadBalancer IPAM and L2 Service Announcement

Cilium动手实验室: 精通之旅---13.Cilium LoadBalancer IPAM and L2 Service Announcement 1. LAB环境2. L2公告策略2.1 部署Death Star2.2 访问服务2.3 部署L2公告策略2.4 服务宣告 3. 可视化 ARP 流量3.1 部署新服务3.2 准备可视化3.3 再次请求 4. 自动IPAM4.1 IPAM Pool4.2 …...

Spring Security 认证流程——补充

一、认证流程概述 Spring Security 的认证流程基于 过滤器链&#xff08;Filter Chain&#xff09;&#xff0c;核心组件包括 UsernamePasswordAuthenticationFilter、AuthenticationManager、UserDetailsService 等。整个流程可分为以下步骤&#xff1a; 用户提交登录请求拦…...

WEB3全栈开发——面试专业技能点P7前端与链上集成

一、Next.js技术栈 ✅ 概念介绍 Next.js 是一个基于 React 的 服务端渲染&#xff08;SSR&#xff09;与静态网站生成&#xff08;SSG&#xff09; 框架&#xff0c;由 Vercel 开发。它简化了构建生产级 React 应用的过程&#xff0c;并内置了很多特性&#xff1a; ✅ 文件系…...