PAT Advanced Level (1081~1087)

PAT (Advanced Level) Practice python解法合集 1001 A+B Format 1002 A+B for Polynomials 1003 Emergency 1004 Counting Leaves 1005 Spell It Right 1006 Sign In and Sign Out 1007 Maximum Subsequence Sum 1008 Elevator 1009 Product of Polynomials 1010 R... 阅读详情

PAT 1081 Rational Sum

链接:http://www.patest.cn/contests/pat-a-practise/1081

代码:注意有总和为零的情况,此时要输出“0”

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
long long gcd(long long x,long long b)
{
    long long c;
    for(;b!=0;)
    {
        c=x%b;
        x=b;
        b=c;
    }
    return x;
}
int main()
{
    int n;
    long long a,b,c,d,e;
    scanf("%lld",&n);
    scanf("%lld/%lld",&a,&b);
    for(int i=1;i<n;++i)
    {
        scanf("%lld/%lld",&c,&d);
        e=gcd(b,d);
        e=b/e*d;
        a=a*(e/b);
        c=c*(e/d);
        a=a+c;
        b=e;
    }
    long long f=a/b;
    a=a%b;
    if(f!=0||a==0)
    {
        printf("%lld",f);
    }
    if(a!=0)
    {
        c=gcd(a,b);
        if(f==0)
            printf("%lld/%lld",a/c,b/c);
        else
            printf(" %lld/%lld",a/c,b/c);
    }
    printf("\n");
    return 0;
}

PAT 1082  Read Number in Chinese

链接:http://www.patest.cn/contests/pat-a-practise/1082

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
string d[11]= {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
string q[11]= {"", "Shi", "Bai", "Qian", "Wan", "Shi", "Bai", "Qian", "Yi"};
vector<int> res;
vector<string> ans;
int main()
{
    int n;
    scanf("%d",&n);
    if(n==0)
    {
        printf("ling\n");
    }
    else
    {
        int len=0;
        if(n<0)
        {
            printf("Fu ");
            n=-n;
        }
        for(; n>0; n/=10)
        {
            res.push_back(n%10);
        }
        for(; len<res.size()&&res[len]==0; ++len);
        if(len<8)
        {
            for(int i=len; i<res.size(); ++i)
            {
                if(i!=0&&(res[i]!=0||i%4==0))
                {
                    ans.push_back(q[i]);
                }
                ans.push_back(d[res[i]]);
            }
            for(int i=ans.size()-1,j; i>=0; --i)
            {
                j=0;
                if(i!=ans.size()-1)
                    printf(" ");
                for(; i>=0&&ans[i]=="ling"; --i,++j);
                if(j>0&&ans[i]!="Wan")
                    printf("ling ");
                printf("%s",ans[i].c_str());
            }
            printf("\n");
        }
        else
        {
            printf("%s Yi\n",d[res[len]].c_str());
        }
    }
    return 0;
}

PAT 1083  List Grades

链接:http://www.patest.cn/contests/pat-a-practise/1083

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
struct student
{
    char name[15];
    char id[15];
    int grade;
} stu[100005];
bool cmp(const struct student &a,const struct student &b)
{
    return a.grade<b.grade;
}
int main()
{
    int n,a,b;
    int maxGrade=-1,minGrade=999;
    scanf("%d",&n);
    for(int i=0; i<n; ++i)
    {
        scanf("%s %s %d",stu[i].name,stu[i].id,&stu[i].grade);
        if(stu[i].grade>maxGrade) maxGrade=stu[i].grade;
        if(stu[i].grade<minGrade) minGrade=stu[i].grade;
    }
    sort(stu,stu+n,cmp);
    scanf("%d%d",&a,&b);
    if(a>b)
    {
        a=a^b;
        b=a^b;
        a=a^b;
    }
    if(b<minGrade||a>maxGrade)
    {
        printf("NONE\n");
    }
    else
    {
        int idxA=0;
        int idxB=n-1;
        for(;idxA<n&&stu[idxA].grade<a;++idxA);
        for(;idxB>=0&&stu[idxB].grade>b;--idxB);
        //printf("%d\n",idxB-idxA+1);
        for(int i=idxB;i>=idxA;--i)
            printf("%s %s\n",stu[i].name,stu[i].id);
    }
    return 0;
}

PAT 1086  Tree Traversals Again

链接:http://www.patest.cn/contests/pat-a-practise/1086

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
struct point
{
    int sons[2];
} node[35];
bool first=true;
int n,m,root;
void postorder(int idx)
{
    for(int i=0; i<2; ++i)
        if(node[idx].sons[i]!=-1)
            postorder(node[idx].sons[i]);
    if(first)
    {
        printf("%d",idx);
        first=false;
    }
    else
        printf(" %d",idx);
}
int inorder()
{
    int id=-1;
    char s[10];
    if(m<2*n)
    {
        scanf("%s",s);
        if(strcmp(s,"Push")==0)
        {
            scanf("%d",&id);
            if(m==0) root=id;
            ++m;
        }
        else
        {
            ++m;
            return -1;
        }
        node[id].sons[0]=inorder();
        node[id].sons[1]=inorder();
    }
    return id;
}
int main()
{
    m=0;
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
    {
        node[i].sons[0]=node[i].sons[1]=-1;
    }
    inorder();
    postorder(root);
    return 0;
}

PAT 1087 All Roads Lead to Rome

链接:http://www.patest.cn/contests/pat-a-practise/1087

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
struct road
{
    vector<int> path;
    int costSum;
    int happinessSum;
}tmp;
map<int,string> idToName;
map<string,int> nameToId;
map<int,int> idToHappiness;
vector<int> path;
vector<struct road> ans;
bool visited[205];
int mapx[205][205];
int n;
void dfs(int st,int ed,int costSum,int happiniessSum)
{
    if(st==ed)
    {
        tmp.path.clear();
        int len=path.size();
        for(int i=0;i<len;++i)
            tmp.path.push_back(path[i]);
        tmp.costSum=costSum;
        tmp.happinessSum=happiniessSum;
        ans.push_back(tmp);
        return;
    }
    for(int i=0;i<n;++i)
    {
        if(mapx[st][i]>0&&(!visited[i]))
        {
            path.push_back(i);
            costSum+=mapx[st][i];
            happiniessSum+=idToHappiness[i];
            visited[i]=true;
            dfs(i,ed,costSum,happiniessSum);
            visited[i]=false;
            costSum-=mapx[st][i];
            happiniessSum-=idToHappiness[i];
            path.pop_back();
        }
    }
}
bool cmp(const struct road &a,const struct road &b)
{
    return a.costSum!=b.costSum?(a.costSum<b.costSum):(a.happinessSum!=b.happinessSum?(a.happinessSum>b.happinessSum):(a.happinessSum/(double)(a.path.size()-1)>b.happinessSum/(double)(b.path.size()-1)));
}
int main()
{
    int k,a,endCity;
    char c[15],s[15];
    scanf("%d%d%s",&n,&k,c);
    idToName.insert(make_pair(0,string(c)));
    nameToId.insert(make_pair(string(c),0));
    idToHappiness.insert(make_pair(0,0));
    for(int i=1; i<n; ++i)
    {
        scanf("%s%d",c,&a);
        idToName.insert(make_pair(i,string(c)));
        nameToId.insert(make_pair(string(c),i));
        idToHappiness.insert(make_pair(i,a));
        if(strcmp(c,"ROM")==0) endCity=i;
    }
    memset(mapx,0,sizeof(mapx));
    for(int i=0,ida,idb;i<k;++i)
    {
        scanf("%s%s%d",c,s,&a);
        ida=nameToId[string(c)];
        idb=nameToId[string(s)];
        mapx[ida][idb]=mapx[idb][ida]=a;
    }
    memset(visited,false,sizeof(visited));
    path.push_back(0);
    visited[0]=true;
    dfs(0,endCity,0,0);
    sort(ans.begin(),ans.end(),cmp);
    int out=ans[0].costSum,countx=1;
    for(;out==ans[countx].costSum;++countx);
    printf("%d %d %d %d\n",countx,ans[0].costSum,ans[0].happinessSum,(int)(ans[0].happinessSum/(double)(ans[0].path.size()-1)));
    printf("%s",idToName[ans[0].path[0]].c_str());
    for(int i=1;i<ans[0].path.size();++i)
         printf("->%s",idToName[ans[0].path[i]].c_str());
    printf("\n");
    return 0;
}




ubuntu18.04 升级Ubuntu 20.04 Ubuntu 18.04升级20.04指南:首先备份重要数据,更新当前系统并检查新版本可用性(sudo do-release-upgrade -c)。确认升级后执行sudo do-release-upgrade,按提示完成操作。升级过程需耐心等待,完成后重启系统。注意:升级前务必备份数据,确保系统为最新版本,以降低风险。升级后即可使用Ubuntu 20.04系统。 阅读详情

相关推荐

FreeSWITCH编译安装详细文档

本文档详细介绍了在Ubuntu 22.04系统上从源码编译安装FreeSWITCH的完整流程。主要内容包括:1)系统环境准备和依赖库安装;2)关键依赖库spandsp和sofia-sip的编译安装;3)FreeSWITCH源码的特定版本(v1.6.0)编译配置,包括禁用SignalWire模块的配置方法;4)系统服务配置,包括创建专用用户、设置权限以及配置systemd服务文件。文档特别提供了版本控制说明,确保后期能切换到相同的版本环境,并附有详细的命令操作步骤和注意事项。

唯有代码让我痴狂 1369

pat-1087【最短路径】

最短路径

知识源于积累 2082

LSTM量化选股实战:从数据清洗到回测归因的工程化闭环

LSTM(长短期记忆网络)是一种专为建模长程依赖而设计的循环神经网络,其门控机制能有效应对金融时序数据的非线性、高噪声与动态演化特性。相比传统统计模型或简单RNN,LSTM在股价趋势建模中展现出更强的鲁棒性与泛化能力,尤其适合处理日频多因子时序信号。其技术价值不仅在于提升预测精度,更在于支撑可归因、可审计的量化策略工程实践——从特征构建、标签定义到滚动回测,每一步都需严防未来信息泄露与过拟合风险。典型应用场景包括A股多因子选股、行业轮动信号生成及Alpha组合优化。本文聚焦LSTM在真实量化场景中的落地难点

weixin_33158887的博客 399

PAT甲级1087

1087. All Roads Lead to Rome (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Indeed there are many different tou

湛蓝的天空 1000

Figure 03人形机器人与Helix端到端控制系统:具身智能突破深度解析

2026年5月,Figure AI的Figure 03人形机器人在一场震撼业界的直播中完成了长达200小时的连续全自动作业,分拣近25万个包裹,零故障。这一里程碑式的成就标志着人形机器人正式从「实验室展示」迈入「规模化商用」阶段。本文深入剖析Figure 03的核心技术——Helix端到端神经网络控制系统,包括System 0/1/2三层架构、视觉运动策略、全身协同控制等关键技术,并提供完整的Python/Go代码示例,帮助开发者理解具身智能的核心原理与实现路径。关键词。

shao.bing的专栏 998

机器视觉学习(七)—— 卷积、边缘和滤波器

卷积运算、垂直边缘与水平边缘、滤波器

歆歆~黯了 2740

PAT甲级 A1087

PAT甲级 A1087 题目详情 1087 All Roads Lead to Rome (30分) Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness. Input Specification: Each input f

weixin_44065549的博客 311

别再只盯着轨迹线了!FLUENT DPM后处理实战:从粒子采样到直方图报告的完整流程

本文详细介绍了FLUENT DPM后处理的完整流程,从粒子采样到直方图报告的实战技巧。通过设置采样面、分析.dpm文件数据以及创建加权直方图,帮助工程师获取粒子速度、粒径分布等定量信息,提升多相流模拟的深度分析能力。特别适合需要超越轨迹线分析的CFD工程师。

weixin_28730353的博客 279

【ACM】- PAT. A1087All Roads Lead to Rome 【图 - 最短路径】

题目链接 题目分析 给出无向图,边和结点都有权重,查找最短路径; 当最短路径有多条时,选择结点权重总和最大的那条,若还有多条,选择平均结点权重最大的一条路径; 解题思路 使用Dijkstra()算法 查找最短路径; 本题满足最优子结构,故对于多条最短路径,可以在查找过程中就判断那条最佳(判断稍复杂), 也可以保存所有路径,最后筛选! 注意点: 结点是以三位大写字母组成的名字给...

三个石头 398

计算机组成原理(第三版)唐朔飞-第七章指令系统-课后习题

机器字长是指CPU一次能处理数据的位数通常与CPU的寄存器位数有关。指令字长是指机器指令中二进制代码的总位数。存储字长是指存储单元中存放二进制代码的总位数。三者可以相等也可以不等视不同机器而定。答:OP(4位)A1(6位)A_1(6位)A1​(6位)A2(6位)A_2(6位)A2​(6位)设二地址指令格式为该指令系统的基本格式,4位操作码共有16种编码,其中13种用来定义二地址指令,还剩3种可用作扩展标志。一地址指令条数=3∗26=192。

weixin_45735391的博客 7万+

飞牛fnNAS搭建个人小账本

本文介绍了如何在飞牛NAS上部署ezBookkeeping个人记账应用。该开源工具支持多平台使用,具备双因素认证、多级分类等功能。文章详细讲解了Docker激活、镜像下载、容器部署等步骤,并展示了账户管理、交易记录等基础操作。同时指导用户通过ZeroTier实现远程访问,方便随时随地使用个人记账系统。该方案既保障了数据隐私,又提供了专业记账功能,适合对财务隐私敏感的用户。

dgnankai的专栏 782

PAT A1087

方法:Dijkstra+DFS。 注意点:1,求平均幸福值时,不包括起始点;2,优先级:距离最短>总幸福值>平均幸福值。 #include #include #include #include #include using namespace std; const int INF=10000000; const int maxc=210; struct arc{ int next,

weixin_37565706的博客 400

16、AI与无人机助力紧急器官移植及医疗物资运输

本文探讨了AI与无人机(UAV)集成模型在紧急器官移植和医疗物资运输中的应用。传统运输方式受限于交通、时间和环境因素,而基于图神经网络(GNN)的AI-UAV系统可实现高效、智能、全天候的医疗物资配送,具备实时温湿度监控、自动导航和适应复杂地形等优势。文章分析了该模型在血液、器官运输中的关键作用,展示了其在澳大利亚、中国、美国等国的实际应用案例,并通过表格与流程图说明运作机制。同时,文章还探讨了技术、法规和社会层面的挑战及应对策略,展望了未来技术融合、应用拓展和国际合作的发展趋势,凸显其在全球医疗物流中的广

lll78的博客 102

PAT (Advanced Level) Practice 1081~1100

The string APPAPT contains two PAT’s as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters. Now g...

张小艾博客 1587

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

PAT (Advanced Level) 1081 模拟 1021 并查集 树的直径 链式前向星

PAT 1081 代码丑陋,不想改了 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<string,LL>PII; const int maxn=100; LL gcd(LL a,LL b) { return b==0?a:gcd(b,a%b); }...

老铁,干了这碗algorithms的博客 194

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

PAT-Advanced Level(甲级)目录

PAT-Advanced Level(甲级)目录   A1001: PAT:A1001 A+B Format (20 分) A1002: PAT:A1002 A+B for Polynomials (25 分) A1005: PAT:A1005 Spell It Right A1006: PAT:A1006 Sign In and Sign Out (25 分) A1008:  PAT...

Ecloss 595

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

PAT (Advanced Level) Practice 1081 Rational Sum

                                          1081 Rational Sum Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum. Input Specification: Each input file...

Dunk.Wan 234

PAT Advanced Level 1081. Rational Sum (20)

【来源】 1081. Rational Sum (20) 【分析】 暂略,有空来填坑。 【代码】

harmony的专栏 684

PAT (Basic Level) Practice (中文)(参考答案)1061-1120

PAT (Basic Level) Practice (中文)(参考答案)1061-1120

少侠PSY的博客 1041

1081 Rational Sum

题目来源:PAT (Advanced Level) Practice Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case starts with a positive integer N (≤100), follo

weixin_51032998的博客 201

PAT (Advanced Level) Practice A1081 Rational Sum (20 分)(C++)(甲级)(分数相加)

1081 Rational Sum (20 分) Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case sta...

izhxxx的博客 181

PAT (Advanced Level) Practice1081 Rational Sum

PAT (Advanced Level) Practice1081 Rational Sum

mistoffe的博客 117

PAT (Advanced Level) Practice 1081 Rational Sum(20分)【数学:分数】

Given NNN rational numbers in the form numerator/denominator, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case starts with a positive int...

一只小羊 299

PAT (Advanced Level) Practice::1081 Rational Sum

收获:递归法得求最大公约数m,最小公倍数就是a*b/m 变量名字,在清晰易懂的基础上,能短就短 #include<iostream> #include<cmath> using namespace std; struct RationalNumbers { long long numerator; long long...

qq_41228018的博客 160

PAT (Advanced Level)1081 Rational Sum (20分)

GivenNrational numbers in the formnumerator/denominator, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case starts with a positive integerN(≤100), followed in the next lineNrational numb...

zy的博客 145

PAT (Advanced Level) Practice — 1081 Rational Sum (20 分)

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805386161274880 Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum. Input Specific...

Mongo_girl 271
上一篇: PAT Advanced Level (1077~1080)
下一篇: LeetCode OJ : Roman to Integer
ACM_Ted
博客等级 码龄15年 122粉丝 208原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值