赞
踩
【算法1-5】贪心 - 题单 - 洛谷https://www.luogu.com.cn/training/110#problems
- n, t = map(int, input().split())
-
- class node:
- def __init__(self, m, V, v):
- self.m = m
- self.V = V
- self.v = v
- def __lt__(self, other):
- return self.v > other.v
-
- a = []
- for i in range(n):
- m, V = map(int, input().split())
- v = V / m
- temp = node(m, V, v)
- a.append(temp)
- a.sort()
- sum = 0.0
- for i in range(n):
- if t >= a[i].m:
- sum += a[i].V
- t -= a[i].m
- else:
- sum += a[i].v * t
- break
- print('%.2f'%sum)

- n = int(input())
-
- a = [int(i) for i in input().split()]
-
- class node:
- def __init__(self, t, id):
- self.t = t
- self.id = id
- def __lt__(self, other):
- return self.t < other.t
-
- sum = 0.0
- wait = 0.0
- arr = []
- for i in range(n):
- temp = node(a[i], i+1)
- arr.append(temp)
-
- arr.sort()
- for i in range(n):
- sum += wait
- wait += arr[i].t
- sum = sum / float(n)
- for i in range(n-1):
- print(arr[i].id, end=' ')
- print(arr[n-1].id)
- print("%.2f"%sum)

- n = int(input())
-
- class node:
- def __init__(self, l, r):
- self.l = l
- self.r = r
- def __lt__(self, other):
- return self.r < other.r
-
- arr = []
- for i in range(n):
- l, r = map(int, input().split())
- temp = node(l, r)
- arr.append(temp)
-
- arr.sort()
- num = 1
- pre = arr[0].r
- for i in range(1, n):
- if arr[i].l >= pre:
- num += 1
- pre = arr[i].r
- print(num)

[NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G
- import sys
- from queue import PriorityQueue
-
- n = int(input())
- a = [int(i) for i in input().split()]
- q = PriorityQueue()
-
-
- for i in range(n):
- x = a[i]
- q.put(x)
-
- sum = 0
- while True:
- if q.qsize() == 1:
- break
- u = q.get()
- v = q.get()
- q.put(u + v)
- sum += u + v
- print(sum)

- n, k = map(int, input().split())
- a = [int(i) for i in input().split()]
-
- sum = 0
-
-
- if a[0] > k:
- sum += (a[0] - k)
- a[0] = k
- for i in range(1, n):
- lsum = a[i-1] + a[i]
- if lsum > k:
- a[i] -= (lsum-k)
- sum += (lsum-k)
-
- print(sum)

- c = list(input().strip())
- s = int(input())
-
- length = len(c)
- while s > 0:
- for i in range(length-1):
- if c[i] > c[i+1]:
- for j in range(i, length-1):
- c[j] = c[j+1]
- break
- length -= 1
- s -= 1
- i = 0
- while (i <= length-1) and (c[i] == '0'):
- i += 1
- if i == length:
- print('0')
- else:
- for j in range(i, length):
- print(c[j], end='')

- n, s = map(int, input().split())
- a, b = map(int, input().split())
- # print(n, s, a, b)
- class node:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def __lt__(self, other):
- return self.y < other.y
-
- arr = []
-
- for i in range(n):
- x, y = map(int, input().split())
- temp = node(x, y)
- if a + b >= temp.x:
- arr.append(temp)
-
- arr.sort()
- # print(arr)
- i = 0
- cnt = 0
- while True:
- if i >= n:
- break
- if s < arr[i].y:
- break
- s -= arr[i].y
- cnt += 1
- i += 1
- print(cnt)

- n = int(input())
-
- a = [int(i) for i in input().split()]
-
- sum = a[0]
-
- for i in range(1, n):
- if a[i] >= a[i-1]:
- sum += a[i]-a[i-1]
- print(sum)
P1208 [USACO1.3]混合牛奶 Mixing Milk
- n, m = map(int, input().split())
-
- class node:
- def __init__(self, val, num):
- self.val = val
- self.num = num
- def __lt__(self, other):
- return self.val < other.val
-
- a = []
- for i in range(m):
- val, num = map(int, input().split())
- temp = node(val, num)
- a.append(temp)
-
- a.sort()
- sum = 0
- i = 0
- while i < m:
- if n <= a[i].num:
- sum += a[i].val * n
- i += 1
- break
- else:
- sum += a[i].val * a[i].num
- n -= a[i].num
- i += 1
- print(sum)

- w = int(input())
- n = int(input())
- a = []
- for i in range(n):
- a.append(int(input()))
- a.sort(reverse=True)
- num = 0
- for i in range(n):
- if a[i] + a[n-1] > w:
- continue
- else:
- num = i
- break
- l = num
- r = n-1
- while l < r:
-
- if a[l] + a[r] <= w:
- l += 1
- r -= 1
- num += 1
- else:
- l += 1
- num += 1
- if l == r:
- num += 1
- print(num)

- n = int(input())
- a = [int(i) for i in input().split()]
- sum = 0
- a.sort(reverse=True)
- sum += a[0]*a[0]
- l = 0
- r = n-1
- flag = 1
- while l < r:
- sum += (a[l] - a[r]) * (a[l] - a[r])
- l += 1
- sum += (a[l] - a[r]) * (a[l] - a[r])
- r -= 1
- print(sum)
- n=eval(input())
- P=list(map(int,input().split()))
- P=sorted(P)
- Q=[]
- for i in range(n):
- a=P[i]
- Q=sorted(Q,key=lambda x:len(x))
- for j in range(len(Q)+1):
- if j<len(Q):
- if a ==(Q[j][-1]+1):
- Q[j].append(a)
- break
-
- else:
- Q.append([a])
-
- Q=sorted(Q,key=lambda x:len(x))
- print(len(Q[0]))

- n = int(input())
- class node:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def __lt__(self, other):
- return self.x * self.y < other.x * other.y
-
- a = []
- gx, gy = map(int, input().split())
- for i in range(n):
- x, y = map(int, input().split())
- temp = node(x, y)
- a.append(temp)
- a.sort()
- b = []
- for i in range(n):
- num = gx // a[i].y
- gx *= a[i].x
- b.append(num)
- b.sort()
- print(b[n-1])

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。