Mislove Has Lost an Array

本文分享了一个在CodeForces平台上的题目解决思路,针对B题使用Python进行大数运算的方法。作者在面对n上限为500的情况下,采用Python处理大数,通过循环迭代计算最小值和最大值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://codeforces.com/contest/1204/problem/B

日常沙雕,看到个n上限是500直接跑去用python打大数,佛了自己

minn=int(0)
maxx=int(0)
er=1
n,l,r=map(int,input().split())
while(n):
    if(l>0):
        minn+=er
    if(r>0):
        maxx+=er
    er*=2
    n-=1
    l-=1
    r-=1
    if(l==0):
        minn+=n
    if(r==0):
        maxx+=n*(er/2)
        break
print("%d %d" %(minn,maxx))

 

ValueError: setting an array element with a sequence. The requested array has anhomogeneous shape after 1 dimensions. The detected shape was (14,) + inhomogeneous part. This error occurs when you try to assign a sequence (such as a list) to an element of a NumPy array, but the array has an inhomogeneous shape. To resolve this issue, you can follow these steps: 1. Check the shape of your array: First, check the shape of your array using the `shape` attribute. This will help you understand the dimensions and sizes of your array. 2. Ensure consistent shape: Make sure that all the elements in your array have the same shape. If there are elements with different shapes, you will encounter this error. You can use the `np.shape()` function to check the shape of each element in the array and ensure they are consistent. 3. Convert elements to the same shape: If you find elements with different shapes, you can convert them to the same shape using the `np.reshape()` function. This function allows you to reshape the elements to a desired shape. Here's an example that demonstrates how to fix this error: ```python import numpy as np # Create an array with inconsistent shape arr = np.array([(1, 2), [3, 4, 5], (6, 7, 8, 9)]) # Check the shape of the array print(arr.shape) # Output: (3,) # Reshape the elements to the same shape arr = np.array([np.reshape(x, (3,)) for x in arr]) # Check the shape of the array again print(arr.shape) # Output: (3, 3) ``` By reshaping the elements to the same shape, you can avoid the ValueError and ensure that the array has a homogeneous shape.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值