UVa #12627 Erratic Expansion (例题8-12)

像这样的明显2^k的数据,我觉得应该直接反应出递归分治法。


对于具体如何做这个D&C,Rujia给的思路真是很赞,非常值得学习。


通过仔细的观察和分析,会发现这些气球有个特点:

上半部分的左半边和右半边,以及下半部分的左半边,都全等于前一个时刻的状态。下半部分的右半边则全部是蓝气球,不予考虑

因此,我们只需要将[A,B] 这个区间分成两部分来看:中线以上的部分和中线以下的部分。

中线以上的部分,等于前一个时刻相同区间红气球数的两倍。中线以下的部分,等于这一时刻的这个区间向上挪半个高度后,在前一个时刻相同区间上的红气球数。

这样就构成了一个递归关系,我们只需要将初始时刻设为1,就可以在O(k)的时间内计算出结果了。


Rujia给的一个很精妙的转化方法:设函数 f(k, i) 为 k 时刻,前 i 行的红气球总数。那么区间 [A,B] 的红气球数就可以表示为 f(k, B) - f(k, A)

这里的解释我觉得书上说的相当清楚啦

这样做的好处我觉得是避免了拆分区间,从而避免了中线附近边界值的讨论。



Run Time: 0.016s

#define UVa  "LT8-12.12627.cpp"
char fileIn[30] = UVa, fileOut[30] = UVa;

#include<cstring>
#include<cstdio>

using namespace std;

//Global Variables. Reset upon Each Case!
int T, K, A, B;
long long c[35];
/

long long f(int k, int i) {
    if(!i) return 0;
    if(!k) return 1;
    if(i <= 1<<(k-1)) return 2*f(k-1, i);
    else return f(k-1, i-(1<<(k-1))) + 2*c[k-1];
}

int main() {
    c[0] = 1L;
    for(int i = 1; i < 30; i ++) c[i] = 3*c[i-1];

    scanf("%d", &T);
    for(int kase = 1; kase <= T; kase ++) {
        scanf("%d%d%d", &K, &A, &B);
        long long ans = f(K, B) - f(K, A-1);
        printf("Case %d: %lld\n", kase, ans);
    }
    return 0;
}


### STM32F103C8T6 ADC Output Configuration The STM32F103C8T6 microcontroller features an integrated Analog-to-Digital Converter (ADC) that can convert analog signals into digital values with a resolution of up to 12 bits[^1]. The configuration process involves several key steps, including setting the clock source and frequency for the ADC peripheral. For configuring the ADC output: - **Clock Setup**: Ensure the ADC clock does not exceed 14 MHz; otherwise, conversion results may be inaccurate. This is achieved by adjusting the APB2 prescaler in the RCC (Reset and Clock Control) settings[^2]. - **Channel Selection**: Choose which channels will participate in conversions using `ADC_ChannelConfig` function calls within the initialization code. Channels are selected based on pin connections and application requirements[^3]. - **Resolution Setting**: Set the desired data alignment (left or right justified) via software configuration parameters when initializing the ADC module[^4]. ```c // Example setup for enabling ADC channel 0 void Configure_ADC(void){ ADC_InitTypeDef ADC_InitStructure; // Enable clocks... RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC1, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); ADC_DeInit(ADC1); ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1,&ADC_InitStructure); } ``` When troubleshooting issues related to ADC outputs: - Verify correct wiring between sensors/inputs and corresponding MCU pins. - Confirm proper power supply levels as insufficient voltage might lead to erratic readings[^5]. - Check if external components like resistors affect signal integrity before reaching the input stage[^6]. --related questions-- 1. How do different sampling rates impact ADC accuracy? 2. What methods exist for calibrating the internal reference voltages used by the ADC? 3. Can multiple ADC channels operate simultaneously without interference? 4. Are there specific guidelines regarding PCB layout near ADC inputs? 5. Which libraries provide support functions for handling ADC interrupts efficiently?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值