So Who's Counting? by Erin McHugh and Emily Luchetti

本篇汇集了多位知名人士关于年龄增长与生活态度的深刻见解,从Stephen King的‘忙于生活或忙于死亡’到Tibetan proverb的‘半食双行,笑三倍,爱无量’,每句话都是对生活的热爱与智慧的体现。

So Who's Counting? The Little Quote Book about Growing Older and Still Kicking Ass by Erin McHugh and Emily Luchetti


Get busy living or get busy dying.

Stephen King

//

Don’t wait. The time will never be just right.

Napoleon Hill

//

The secret of long life is double careers. One to about age sixty, then another for the next thirty years.

--David Ogilvy

//

The only safe thing is to take a change.

--Mike Nichols

//

I wake up every day and I think, “I’m breathing! It’s a good day.”

Eve Ensler

//

For me, every hour is grace.

--Elie Wiesel

//

I prefer to be a beautiful woman of my age than try desperately to look 30.

Demi Moore

//

Nobody looks good when they get old . . . but what the hell can you do about it? Nothing. So you may as well ignore it as best you can and just be who you are.

Grace Slick

//

Look what you’ve already come through! Don’t deny it. Say I’m stronger than I thought I was.

Maya Angelou

//

If you always do what interests you, at least one person is pleased.

Katharine Hepburn

//

The secret to living well and longer is: Eat half, walk double, laugh triple, and love without measure.

Tibetan proverb

//

Man arrives as a novice at each age of his life.

Nicolas Chamfort

//

I’m not into nostalgia, and I only look back to find lessons.

Ian Schrager

//

All experience is good experience.

--Meredith Vieira

//

I am my own experiment. I am my own work of art.

--Madonna Ciccone

//

A man who dares to waste one hour of time has not discovered the value of life.

Charles Darwin

//

When I stand before God at the end of my life, I would hope that I would not have a single bit of talent left, and could say, “I used everything you gave me.”

Erma Bombeck

Counting Haybales S” 通常是美国信息学奥林匹克竞赛(USACO)里的一道题目。这道题主要围绕干草捆计数展开。 ### 问题描述 给定一个数轴,上面有 $N$ 个干草捆的位置,以及 $Q$ 个询问,每个询问包含一个区间 $[A, B]$,需要计算在该区间内干草捆的数量。 ### 解题思路 1. 先将所有干草捆的位置进行排序。 2. 针对每个询问 $[A, B]$,运用二分查找来找出第一个位置大于等于 $A$ 的干草捆和第一个位置大于 $B$ 的干草捆。 3. 通过这两个位置的差值得到该区间内干草捆的数量。 ### 代码实现 ```python # 读取输入 n, q = map(int, input().split()) haybales = sorted(map(int, input().split())) # 二分查找函数 def lower_bound(arr, x): left, right = 0, len(arr) while left < right: mid = (left + right) // 2 if arr[mid] < x: left = mid + 1 else: right = mid return left def upper_bound(arr, x): left, right = 0, len(arr) while left < right: mid = (left + right) // 2 if arr[mid] <= x: left = mid + 1 else: right = mid return left # 处理询问 for _ in range(q): a, b = map(int, input().split()) # 计算区间内干草捆的数量 count = upper_bound(haybales, b) - lower_bound(haybales, a) print(count) ``` ### 复杂度分析 - 时间复杂度:排序的时间复杂度为 $O(N \log N)$,每次二分查找的时间复杂度为 $O(\log N)$,总共有 $Q$ 个询问,所以总的时间复杂度为 $O(N \log N + Q \log N)$。 - 空间复杂度:主要是存储干草捆位置的数组,空间复杂度为 $O(N)$。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值