1069 The Black Hole of Numbers

按题意模拟…

#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);string N; cin >> N;array<int, 4> a{}, b{};for (int i = 0; i < N.size(); i++) {a[i] = b[i] = N[i] - '0';}auto atoi = [](const array<int, 4>& nums) -> int {int res = 0;for (int i = 0; i < 4; i++) {res += pow(10, 3  - i) * nums[i];}return res;};while (true) {sort(a.begin(), a.end(), greater<>());sort(b.begin(), b.end(), less<>());int x = atoi(a), y = atoi(b);int d = x - y;printf("%04d - %04d = %04d\n", x, y, d);if (d == 6174 || d == 0) break;fill(a.begin(), a.end(), 0);fill(b.begin(), b.end(), 0);string s = to_string(d);for (int i = 0; i < s.size(); i++) a[i] = b[i] = s[i] - '0';}return 0;
}

1070 Mooncake

按 每吨多少钱 排序

#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);int n, M; cin >> n >> M;vector<pair<double, double>> v(n);for (int i = 0; i < n; i++) {cin >> v[i].first;}for (int i = 0; i < n; i++) {cin >> v[i].second;}sort(v.begin(), v.end(), [](const pair<double, double>& A, const pair<double, double>& B) -> bool {return A.second / A.first > B.second / B.first;});double res = 0;for (int i = 0; i < n; i++) {if (M < v[i].first) {res += double(M) / v[i].first * v[i].second;break;} else {M -= v[i].first;res += v[i].second;}}cout << fixed << setprecision(2) << res << endl;return 0;
}

1071 Speech Patterns

cpp切片不太好用,可以写个py

#include <bits/stdc++.h>
using namespace std;int main()
{string s; getline(cin, s);for (int i = 0; i < s.size(); i++) {if (s[i] >= '0' && s[i] <= '9') {continue;} else if (s[i] >= 'a' && s[i] <= 'z') {continue;} else if (s[i] >= 'A' && s[i] <= 'Z') {s[i] = tolower(s[i]);} else s[i] = ' ';}stringstream ss(s);map<string, int> mp;int res = 0;while (ss >> s) {mp[s]++;res = max(res, mp[s]);}for (const auto& [a, b] : mp) {if (b == res) {cout << a << ' ' << b << '\n';break;}    }return 0;
}

1072 Gas Station

理解题意 A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible.先按最短距离从大到小排(也可以理解,毕竟是加油站,远一点为了安全。),然后再按平均距离从小到大排,然后再按id从小到大排。
因为是一个点到所以house距离之和,显然是单源最短路,dijkstra就可以了。
G1可以转为1001,这样映射一下。输出的时候再转回来。
还有注意四舍五入…

 #include <bits/stdc++.h>
using namespace std;using i64 = long long;static constexpr i64 inf = 0x3f3f3f3f3f;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);vector<vector<pair<int, i64>>> graph(1020);int N, M, K, D; cin >> N >> M >> K >> D;while (K--) {string a, b, c; cin >> a >> b >> c;int C = stoi(c), A, B;if (a[0] == 'G') {A = 1000 + stoi(a.substr(1));} else A = stoi(a);if (b[0] == 'G') {B = 1000 + stoi(b.substr(1));} else B = stoi(b);graph[A].emplace_back(B, C);graph[B].emplace_back(A, C);}auto dijkstra = [&](int start) -> vector<i64> {vector<i64> dist(1020, inf);dist[start] = 0;priority_queue<pair<i64, int>, vector<pair<i64, int>>, greater<>> pq;pq.push({0, start});while (!pq.empty()) {auto [d, u] = pq.top();pq.pop();if (d > dist[u]) continue;for (const auto& [v, w] : graph[u]) {if (d + w < dist[v]) {dist[v] = d + w;pq.push({dist[v], v});}}}return dist;};struct GAS {int mix, id;double ave;explicit GAS(int _m, int _id, double _a): mix(_m), id(_id), ave(_a) {}};vector<GAS> res;for (int i = 1001; i <= 1000 + M; i++) {const auto& d = dijkstra(i);i64 dis = 0, mi = inf;for (int j = 1; j <= N; j++) {if (d[j] > D) goto ne;dis += d[j];mi = min(d[j], mi);}res.emplace_back(mi, i, round(double(dis) / double(N) * 10) / 10);ne: continue;}sort(res.begin(), res.end(), [](const GAS& A, const GAS& B) -> bool {if (A.mix == B.mix) {if (A.ave == B.ave) return A.id < B.id;return A.ave < B.ave;} return A.mix > B.mix;});if (res.empty()) {cout << "No Solution\n";} else {const auto& r = res[0];cout << "G" + to_string(r.id - 1000) + "\n";cout << fixed << setprecision(1) << double(r.mix);cout << ' ' << fixed << setprecision(1) << r.ave;}return 0;
}

PTA甲 1069~1072题解相关推荐

  1. PTA甲 1152~1155题解

    1152 Google Recruitment 暴力判断质数就可以了. O ( N ⋅ 1 0 k 2 ) O(N\cdot10^{\frac{k}{2}}) O(N⋅102k​) #include ...

  2. PTA(Basic Level) 1072:开学寄语(C语言实现)

    PTA(Basic Level) 1072:开学寄语(C语言实现) #include <stdio.h>int main() {int n,m,k,i,j,t,count1=0,count ...

  3. 拼题A (PTA) 公共题集题解收录

    仓库地址:PTA: 拼题A(PTA)公共题集的题解 (github.com) 该仓库收录 拼题A 公共习题的题解,绝大部分习题都是本人自己的原创代码,如有错误的代码可提交 Issue 推荐使用我开发的 ...

  4. PTA甲1124 Raffle for Weibo Followers (20 point(s))

    强烈推荐,刷PTA的朋友都认识一下柳神–PTA解法大佬 本文由参考于柳神博客写成 柳神的CSDN博客,这个可以搜索文章 柳神的个人博客,这个没有广告,但是不能搜索 还有就是非常非常有用的 算法笔记 全 ...

  5. PTA 520钻石争霸赛题解

    第一题 7-1 考试周 (5分) 考试周快到了,浙江大学的电子屏又调皮了-- 本题请你帮小编写一个自动倒计时的程序,对给定的日期(例如"腊八"就对应 8)和倒计时天数(例如电子屏上 ...

  6. PTA 基础编程题 题解

    7-1 厘米换算英尺英寸 (15 point(s)) 查看题解   7-2 然后是几点 (15 point(s)) 查看题解   7-3 逆序的三位数 (10 point(s)) 查看题解   7-4 ...

  7. PTA乙级 1069 微博转发抽奖——20分

    小明PAT考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔N个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一行给出三个正整数M(<= 1000).N ...

  8. pta初级题库题解1~50

    #7.1判断素数 7-1 判断素数. 判断输入的整数是否是素数,如果是则输出"1",否则输出"0". 输入格式: 输入一个整数. 输出格式: 按照要求输出1或者 ...

  9. PTA 自助扫码 题解

    描述:          扫码支付如今已普及应用在大型超市,街边小贩等多个消费支付的场景,刷脸支付也在商超零售场景逐渐应用,很多的大型超市引进自助收银系统,实现自助结账应用. 已知某超市有自助收银机m ...

最新文章

  1. 你知道为什么Java的main方法必须是public static void?
  2. go 怎么遍历json数据_json数据怎么处理 好难 啊!
  3. 近期活动盘点:三创对接会——先进制造专场
  4. Mysql 源码安装
  5. jquery submit()不能提交表单的解决方法
  6. Algorithm:C++语言实现之链表相关算法(单链公共结点问题、一般LCA、括号匹配、最长括号匹配、逆波兰表达式Reverse Polish Notation、直方图矩形面积、收集雨水问题)
  7. Android -- Fragment动画异常Unknown animation name: objectAnimator
  8. 千兆以太网线和水晶头的制作方法
  9. Chrome 或将于2018年正式弃用 HPKP 公钥固定标准
  10. HTML+CSS+JS实现 ❤️canvas圆形水波进度条动画特效❤️
  11. 任务管理器中arcsom.exe和arcsoc.exe的个数问题
  12. PLC编程语言都在这里了!
  13. Soul App 后台Api接口
  14. 三箭暴雷造清算 回顾三箭资本Zhu Su黑以太坊奶自己投资项目的黑历史
  15. 网页游戏常见外挂原理及防御
  16. 大庆铁人精神与时俱进 石油石化行业如何利用ICT基础设施驱动价值创造?
  17. Teams下载安装教程
  18. 华米科技再发“芯”品,能否唤起智能穿戴设备生态繁荣?
  19. APISpace 分钟级降水预报API接口 免费好用
  20. 一个c加一个g是什么牌子_车标是一个很神奇的存在 那你知道“G”是什么汽车吗?...

热门文章

  1. 用PS制作一只梦幻的小鹿插画
  2. Uber的启动画面是如何制作的
  3. shell编程-数组的使用
  4. React Native 仿 ofo 共享单车 App
  5. 图解TCP/IP 第一章 网络基础知识
  6. java设计模式总结之六大设计原则(有图有例子)
  7. 【转载】测试面试知识点
  8. 聚合接口对接,加油卡,流量充值,话费充值
  9. c语言 __at定位编译报错,盈球新版 -官网
  10. 《挖掘管理价值:企业软件项目管理实战》一2.3 需求分析过程