codeforces706B 【python】
来源:互联网 发布:视频软件 知乎 编辑:程序博客网 时间:2024/05/21 11:21
第一版写法(如下)TLE了,所以得用二分啊
def get_result(wine_price,today_money): for i in range(len(wine_price)): if wine_price[i] > today_money: return i return len(wine_price) n = int(raw_input())wine_price = map(int,raw_input().split())wine_price = sorted(wine_price)q = int(raw_input())for i in range(q): temp = int(raw_input()) print get_result(wine_price,temp)
第二版写法(如下)
def get_index(wine_price,today_money): left = 0 right = len(wine_price) - 1 while left < right: mid = (left + right)/2 if wine_price[mid] <= today_money: left = mid + 1 else: right = mid return rightdef get_result(wine_price,today_money): result = get_index(wine_price,today_money) if result == (len(wine_price)-1) and today_money >= wine_price[-1]: result += 1 return result n = int(raw_input())wine_price = map(int,raw_input().split())wine_price = sorted(wine_price)q = int(raw_input())for i in range(q): temp = int(raw_input()) print get_result(wine_price,temp)
阅读全文
0 0
- codeforces706B 【python】
- codeforces706B(二分)之Interesting drink
- codeforces706B Interesting drink 排序+二分查找
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- 性能优化登顶安卓阵营,vivo X20闪耀王者荣耀巅峰之战
- 从源头重塑整个机器视觉行业,这家中国公司要搞事情
- OSGI实战教程【Spring DM】编写一个简单的Bundle组件
- 57. Insert Interval
- Windows 10 秋季创作者更新将于10月17日推出,混合现实功能成亮点
- codeforces706B 【python】
- Linux基础知识
- LVS+Keepalived实现高可用负载均衡(Web群集)
- Centos中导入sql文件到mysql数据库
- linux进程管理
- 剑指offer——面试题22:栈的压入、弹出序列
- 链表和二叉树
- 低通、高通、带通、带阻、状态可调滤波器【1】
- vivo X20 Plus预售开启:极致全面屏+超长续航畅玩更自在