python记录(10.23)

【PAT A1065】A+B and C(64bit)

Given three integers A, B and C in (−263,263), you are supposed to tell whether A+B>C.

Input Specification:

The first line of the input gives the positive number of test cases, T (≤10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.

Output Specification:

For each test case, output in one line Case #X: true if A+B>C, or Case #X: false otherwise, where X is the case number (starting from 1). Each line should ends with '\n'.

Sample Input:

3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0

Sample Output:

Case #1: false
Case #2: true
Case #3: false

Thanks to Jiwen Lin for amending the test data.

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

python解法:

T = eval(input())
for i in range(T):
    a,b,c = map(int,input().split())
    if a+b > c:
        print(f"Case #{i+1}: true")
    else:
        print(f"Case #{i+1}: false")
        

如果用C++还要判断溢出,如果两个正数之和等于负数,或者两个负数之和等于正数,那么就是溢出。

https://zhuanlan.zhihu.com/p/399590503

 【PAT A1002】A+B for Polynomials

This time, you are supposed to find A+B where A and B are two polynomials.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:

K N1​ aN1​​ N2​ aN2​​ ... NK​ aNK​​

where K is the number of nonzero terms in the polynomial, Ni​ and aNi​​ (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10,0≤NK​<⋯<N2​<N1​≤1000.

Output Specification:

For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

Sample Input:

2 1 2.4 0 3.2
2 2 1.5 1 0.5

Sample Output:

3 2 1.5 1 2.9 0 3.2

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

第一次解:

A = [eval(x) for x in list(input().split())]
B = [eval(x) for x in list(input().split())]
Adict = {}
Bdict = {}
for i in range(1,len(A),2):
    Adict[A[i]] = A[i+1]
for i in range(1,len(B),2):
    Bdict[B[i]] = B[i+1]

for key,value in Bdict.items():
    if key in Adict:
        Adict[key] += value
    else:
        Adict[key] = value
C = dict(sorted(Adict.items(),key = lambda x:x[0],reverse=True))
print(len(C),end="")
for key,value in C.items():
    print(f" {key} {value}",end="")

思考1:因为输入有小数有整数,不能用map(int,..)来解,想到用eval(代码行:1)

在思考过程中看到一个帖子,虽然与本题无关,但可以记录一下:

Python 如何将字符串转为字典 - 菜鸟学院

思考2:两个字典怎么相加键相同的值?

参考https://www.jb51.net/article/157352.htm

 

 

 结果:

第二次解:

增加了多项式加减法后,0项的删除。参考输入,只有非零项。 

删除字典:pop和del的区别在于有无返回值。形式:A.pop(key)    del A[key]

python基础之字典的删除_jiankang66的博客-CSDN博客_python 字典删除

A = [eval(x) for x in list(input().split())]
B = [eval(x) for x in list(input().split())]
Adict = {}
Bdict = {}
for i in range(1,len(A),2):
    Adict[A[i]] = A[i+1]
for i in range(1,len(B),2):
    Bdict[B[i]] = B[i+1]

for key,value in Bdict.items():
    if key in Adict:
        Adict[key] += value
        if Adict[key] == 0:
            del Adict[key]
    else:
        Adict[key] = value
C = dict(sorted(Adict.items(),key = lambda x:x[0],reverse=True))
print(len(C),end="")
for key,value in C.items():
    print(f" {key} {value}",end="")

 第三次解:

还有测试点没通过。可能是格式问题。仔细阅读:

Please be accurate to 1 decimal place.

翻译:请精确到小数点后一位

A = [eval(x) for x in list(input().split())]
B = [eval(x) for x in list(input().split())]
Adict = {}
Bdict = {}
for i in range(1,len(A),2):
    Adict[A[i]] = A[i+1]
for i in range(1,len(B),2):
    Bdict[B[i]] = B[i+1]

for key,value in Bdict.items():
    if key in Adict:
        Adict[key] += value
        if Adict[key] == 0:
            del Adict[key]
    else:
        Adict[key] = value
C = dict(sorted(Adict.items(),key = lambda x:x[0],reverse=True))
print(len(C),end="")
for key,value in C.items():
    print(f" {key} {value:.1f}",end="")

 【PAT A1009】Product of Polynomials

This time, you are supposed to find A×B where A and B are two polynomials.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:

K N1​ aN1​​ N2​ aN2​​ ... NK​ aNK​​

where K is the number of nonzero terms in the polynomial, Ni​ and aNi​​ (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤NK​<⋯<N2​<N1​≤1000.

Output Specification:

For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.

Sample Input:

2 1 2.4 0 3.2
2 2 1.5 1 0.5

Sample Output:

3 3 3.6 2 6.0 1 1.6

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

看不懂怎么运算的,之后再看

可以参考

 https://www.bilibili.com/read/cv9778023/

 Python itertools 模块中的 product 函数_CodeLogs的博客-CSDN博客_python product

10.27补充

系数相乘,指数相加

 

A = [eval(x) for x in list(input().split())]
B = [eval(x) for x in list(input().split())]
Adict = {}
Bdict = {}
C = {}
for i in range(1,len(A),2):
    Adict[A[i]] = A[i+1]
for i in range(1,len(B),2):
    Bdict[B[i]] = B[i+1]

for key,value in Bdict.items():
    for key1,value1 in Adict.items():
        C[key + key1] = C.get(key + key1,0) + value*value1
        if C[key + key1] == 0:
            del C[key + key1]
C = dict(sorted(C.items(),key = lambda x:x[0],reverse=True))
print(len(C),end="")
for key,value in C.items():
    print(f" {key} {value:.1f}",end="")

 

### 10.23 MHz时钟配置和应用 #### 配置方法 对于涉及10.23 MHz时钟的应用场景,特别是针对全球定位系统(GPS),该频率与时钟同步机制紧密关联。在GPS系统中,卫星上的原子钟被设定为运行在一个精确控制下的频率下,即10.23 MHz,这有助于保持整个系统的高精度计时性能[^2]。 为了确保地面设备能够与这些卫星进行有效的通信,并维持所需的时间同步水平,在设置本地振荡器至10.23 MHz的过程中需注意以下几点: - **硬件选择**:选用具有低相位噪声特性的晶体振荡器作为稳定源; - **温度补偿**:考虑到环境变化可能引起频率漂移,应采用温控措施来减少这种影响; - **校准过程**:通过外部参考信号定期调整内部时基,以消除长期累积误差。 ```python # Python代码示例展示如何模拟简单的10.23MHz时钟生成函数 import numpy as np def generate_10p23mhz_clock(samples_per_period=10, sample_rate=int(1e6)): """Generate a simulated 10.23 MHz clock signal.""" period = int(sample_rate / (10.23 * samples_per_period)) time_vector = np.arange(period) / float(sample_rate) waveform = np.zeros_like(time_vector) for i in range(len(waveform)): if i % samples_per_period == 0: waveform[i] = 1 return time_vector, waveform ``` 此Python脚本提供了一个简单的方法来创建一个周期性脉冲序列,其重复率为每秒钟大约10.23百万次,可用于测试目的或教育用途。 #### 应用实例 除了上述提到的GPS领域外,10.23 MHz时钟还在其他方面发挥着重要作用,比如无线电信号处理、雷达测距以及各种精密测量仪器的设计当中。特别是在军事活动中,由于对时间和空间坐标的准确性有着极高要求,因此基于此类高频时钟构建起来的数据传输链路显得尤为重要[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值