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

C++信息学奥赛一本通-第一部分-基础一-第2章-第5节

C++信息学奥赛一本通-第一部分-基础一-第2章-第5节

2070 数字对调

#include <iostream>using namespace std;int main() {int number; cin >> number;int a = number / 100;int b = number / 10 % 10;int c = number % 100 % 10;int target = c * 100 + b * 10 + a;cout << target;
}

2071 平均分

#include <iostream>using namespace std;int main() {double x, y; cin >> x >> y;double sum_x = x * 87, sum_y = y * 85;double result = (sum_x + sum_y) / (x + y);printf("%.4f", result);
}

2072 歌手大奖赛-增幅减幅都一样那平均不还是一样

#include <iostream>using namespace std;int main() {double a = 9.6;printf("%5.2f", a);
}

2073 三角形面积

#include <iostream>
#include <cmath>using namespace std;int main() {double x, y, z; cin >> x >> y >> z;double p = (x+y+z) / 2.0;double temp = p * (p - x) * (p - y) * (p - z);double s = pow(temp, 0.5);printf("%.3f", s);
}

1029 计算浮点数相除的余

#include <iostream>using namespace std;int main() {double x, y; cin >> x >> y ;double nums = x / y;double remainder = x - (int)nums * y;cout << remainder;
}

1030 计算球的体积-保留小数会四舍五入

#include <iostream>
#define PI 3.14using namespace std;int main() {double r; cin >> r;double V = (PI * r * r *r) * 4 / 3;printf("%.2f", V);
}

1031 反向输出一个三位数-和2070的区别就是补0

#include <iostream>using namespace std;int main() {int number; cin >> number;int a = number / 100;int b = number / 10 % 10;int c = number % 100 % 10;int target = c * 100 + b * 10 + a;printf("%03d", target);
}

1032 大象喝水查

#include <iostream>
#define PI 3.14using namespace std;int main() {double h, r; cin >> h >> r;double V = (PI * r * r) * h;int nums = (int)(20000 / V);printf("%d", nums + 1);
}

1033 计算线段长度

#include <iostream>
#include <cmath>
using namespace std;int main() {double xofa, yofa, xofb, yofb; cin >> xofa >> yofa >> xofb >> yofb;double result = pow(pow(yofb - yofa ,2)+pow(xofb - xofa , 2), 0.5);printf("%.3f",result);
}

1034 计算三角形面积

​ 使用行列式公式计算三角形面积-背的出来就用吧

xa:yb-yc xb:yc - ya xc: ya - yb

#include <iostream>
#include <cmath>using namespace std;
double calculateTriangleArea(double xofa, double yofa, double xofb, double yofb, double xofc, double yofc) {double area = 0.5 * abs((xofa*(yofb - yofc) + xofb*(yofc - yofa) + xofc*(yofa - yofb)));return area;
}
int main() {double xofa, yofa, xofb, yofb, xofc, yofc; cin >> xofa >> yofa >> xofb >> yofb >> xofc >> yofc;double result = calculateTriangleArea(xofa, yofa, xofb, yofb, xofc, yofc);printf("%.2f", result);
}

使用向量-推荐

#include <iostream>
#include <cmath>
using namespace std;
double calculateTriangleArea(double xofa, double yofa, double xofb, double yofb, double xofc, double yofc) {double vecAB_x = xofb - xofa;double vecAB_y = yofb - yofa;double vecAC_x = xofc - xofa;double vecAC_y = yofc - yofa;double cross_product = vecAB_x * vecAC_y - vecAB_y * vecAC_x;return 0.5 * fabs(cross_product);
}int main() {double xofa, yofa, xofb, yofb, xofc, yofc; cin >> xofa >> yofa >> xofb >> yofb >> xofc >> yofc;double result = calculateTriangleArea(xofa, yofa, xofb, yofb, xofc, yofc);printf("%.2f", result);
}

1035 等差数列末项计算

#include <iostream>using namespace std;int main() {int n_of_1, n_of_2, n; cin >> n_of_1 >> n_of_2 >> n;int result = (n_of_2 - n_of_1) * (n-1) + n_of_1;cout << result;
}

1036 A∗BA*BAB问题

unsigned int 最高42亿

#include <iostream>using namespace std;int main() {unsigned int a, b; cin >> a >> b;unsigned int result = a * b;cout << result;
}

1037 计算2的幂

#include <iostream>
#include <cmath>
using namespace std;int main() {unsigned int n; cin >> n;unsigned int result = pow(2,n);cout << result;
}

1038 苹果和虫子

#include <iostream>using namespace std;int main() {int n, x, y; cin >> n >> x >> y;int result = (y % x == 0) ? (n - (y / x)) : (n - (y / x) - 1);if (result < 0) result = 0;cout << result;
}
http://www.dtcms.com/a/321304.html

相关文章:

  • 亚马逊 Alexa + 广告整合:智能语音交互重构电商营销范式
  • AI日报 - 2025年08月08日
  • [科普] AI加速器架构全景图:从GPU到光计算的算力革命
  • vue3 map和filter功能 用法
  • 仅需8W,无人机巡检系统落地 AI 低空智慧城市!可源码交付
  • 远期(Forward)交易系统全球金融市场解决方案报告
  • 智能体协同作战:实现工具调用成功率提升47%的架构奥秘
  • 支付宝「安全发-甲方直发」架构详解及与「安全发ISV模式」对比
  • Python训练营打卡Day26-函数专题2:装饰器
  • 可信数据空间(Trusted Data Space)的技术架构概述
  • matplotlib库和seaborn库
  • 深度学习调参技巧总结
  • 5 种简单方法将 Safari 书签转移到新 iPhone
  • 商品期货场外期权系统解决方案:跨境金融科技赋能大宗商品风险管理
  • duxapp 2025-05-29 更新 兼容鸿蒙C-API方案,现在鸿蒙端可以用于生产
  • 中小业务遭遇网络攻击,防护能力不足的解决办法​
  • 滑动窗口与双指针训练
  • 机器学习概念2
  • 数据库冗余设计:平衡性能与一致性的艺术
  • 机器学习-Logistic Regression
  • Android Studio第一个kotlin项目“Hello Android”
  • 解决Ollama外部服务器无法访问:配置 `OLLAMA_HOST=0.0.0.0` 指南
  • 鲸签云解决互联网行业合同管理难题​
  • 北京-4年功能测试2年空窗-报培训班学测开-第七十一天-面试第二天
  • 内容分发机制研究:实测一款多源短视频聚合App
  • C++中的继承:从基础到复杂
  • 从零构建TransformerP1-了解设计
  • FreeRTOS入门知识(初识RTOS)(一)
  • Nginx 部署前端项目、负载均衡与反向代理
  • Seaborn 学习笔记