- 博客(54)
- 收藏
- 关注
原创 C++入门同步记录#10
#include<iostream>using namespace std;int main() { int s1 = 0, s2 = 0, i1 = 1, i2 = 1; s1 += i1++;//运算后累加 s2 += ++i2;//运算前累加 cout << s1 << s2 << i1 << i2; return 0;}#include<iostream>using name
2021-03-27 15:28:50
111
原创 【递归联系】博物馆大道问题
tr = {(2, 3), (3, 4), (4 ,8), (5, 8), (9, 10)}max_w = 5m = {}# 初始化记忆化表格# key是(宝物组合,最大重量), value是最大价值def thief(tr, w): if tr == set() or w == 0: m[(tuple(tr), w)] = 0 return 0 elif (tuple(tr), w) in m: return m[(tupl
2021-03-24 21:59:39
93
原创 【dp练习】博物馆大道问题
tr = [None, {'w': 2, 'v': 3}, {'w': 3, 'v': 4}, {'w': 4, 'v': 8}, {'w': 5, 'v': 8}, {'w': 9, 'v': 10}]max_w = 20m = {(i, w): 0 for i in range(len(tr)) for w in range(max_w + 1)}print(m)for i in range(1, len(tr)): for w in range(1,
2021-03-24 20:54:25
90
原创 吉林大学ACM集训队选拔赛 B Subset of Five【返回非零解】
n = int(input())nums = list(map(int, input().split()))nums.sort()sum_ = 0nums2 = [0] * nfor i in range(n): sum_ += nums[i] nums2[i] = nums[i] % 5# print(nums2)# print('sum_', sum_)yu = sum_ % 5# print(yu)if yu == 0: print(sum_)elif y
2021-03-24 15:58:26
83
原创 吉林大学ACM集训队选拔赛 A - 777【超时解】
for _ in range(int(input())): n = int(input()) aa = 1 ans = 0 while aa <= n: ans += (n // (aa * 10)) * aa if n // aa % 10 > 7: ans += aa elif n // aa % 10 == 7: ans += (n % aa + 1) ..
2021-03-24 13:48:33
412
原创 dp 找零兑换 代码
def dpMakeChange(coinValueList, change, minCoins, coinsUsed): for cents in range(1, change + 1): # 初始化一个最大值 coinCount = cents # 初始化一下新加的那个硬币 newCoin = 1 for j in [c for c in coinValueList if c <= cents]:
2021-03-24 11:16:48
74
原创 C++入门同步记录#9
/* #include<iostream>using namespace std;int main() { long long n, ans = 0; cin >> n; for (int i = 1; i <= n; i++) { long long factor = 1; for (int j = 1; j <= i; j++) factor *= j; ans +=
2021-03-22 21:43:36
116
原创 C++入门同步记录#8
#include<cstdio>using namespace std;int main() { int n, k, A_sum, B_sum; scanf("%d%d", &n, &k); A_sum = k * (n / k) + ((n / k) * (n / k - 1) * k) / 2; B_sum = (1 + n) * n / 2 - A_sum; printf("%.1f ", double(A_sum) / (n /
2021-03-22 18:44:43
50
原创 秦皇岛CCPC2020 A - Greeting from Qinhuangdao
from fractions import Fractionk = 1for _ in range(int(input())): r, b = map(int, input().split()) r_sum = Fraction(r * (r - 1) / 2) b_sum = Fraction(b * (b - 1) / 2) rb = r * b res = Fraction(r_sum / (r_sum + b_sum + rb)) print("C
2021-03-22 17:57:42
71
原创 【错解】秦皇岛CCPC2020 D - Exam Results
我的错解def plu(maxp): res = 0 for i in range(n): if high[i] <= maxp and high[i] > (maxp * p / 100): res += 1 return resfor _ in range(int(input())): n, p = map(int, input().split()) high = [] low = []
2021-03-22 17:55:40
184
原创 C++入门同步记录#7
#include<iostream>using namespace std;int main() { int yyyy, mm; cin >> yyyy >> mm; switch (mm) { case 1: case 3: case 5: case 7: case 8: case 10 : case 12: cout << 31 << endl; break;
2021-03-20 20:39:13
97
原创 C++入门同步记录#6
#include<iostream>using namespace std;int main() { int x; cin >> x; cout << "Today, I ate " << x << " apple"; if (x > 1) { // if (x != 0 && x != 1){ cout << "s" << endl;
2021-03-20 00:56:24
173
原创 C++入门同步记录#5
#include<cstdio>#include<cmath>using namespace std;int main() { int s, v; scanf("%d%d", &s, &v); int t_walk = ceil(1.0 * s / v) + 10; int from_zero = 60 * (24 + 8) - t_walk; int hh = (from_zero / 60) % 24; int
2021-03-19 00:18:42
57
原创 Codeforces Round #704 (Div. 2) A. Three swimmers
'''11 4ababcadacddabcd'''n, m = map(int, input().split())a1 = input()b1 = input()lst1 = []j = 0for i in b1: while j < n: if a1[j] == i: lst1.append(j) break j += 1 j += 1lst2 = []print(lst1)j ..
2021-03-17 21:12:42
82
原创 Codeforces Round #704 (Div. 2) B. Card Deck
'''441 2 3 451 5 2 4 364 2 5 3 6 111'''for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) arr2 = [] for idx, num in enumerate(arr): arr2.append((num, idx)) arr2.sort(reverse= True)...
2021-03-17 20:30:06
75
原创 2021年度训练联盟热身训练赛第二场 D - Soccer Standings
省略了算总分和累计己方进球数和对方进球数的赘余,for _ in range(int(input())): team_num, match_num = map(int, input().split()) team = list(input().split()) team.sort() dict = {} for i in team: dict[i] = [0] * 6 for k in range(match_num): ...
2021-03-16 11:18:02
148
1
原创 ZOJ 4033 - CONTINUE...?
for _ in range(int(input())): n = int(input()) s = input() lst = [] ans = [0] * n for i in s: lst.append(int(i)) if n % 2 == 1: if ((n // 2 + 1) * n) % 2 == 1: print(-1) continue els..
2021-03-14 22:38:03
93
原创 ZOJ 4025 King of Karaoke
import collectionsfor _ in range(int(input())): n = int(input()) arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) minus = [0] * n for i in range(n): minus[i] = arr2[i] - arr1[i] dict = collect..
2021-03-14 22:36:16
136
原创 ZOJ 4024 peak
for _ in range(int(input())): n = int(input()) nums = list(map(int, input().split())) if n < 3: print('No') continue i, j = 0, 0 for i in range(n-1): if nums[i+1] <= nums[i]: i = i ..
2021-03-14 22:34:54
81
原创 C++入门同步记录#4
/*#include<iostream>using namespace std;int main() { char a, b, c, dot, d; cin >> a >> b >> c >> dot >> d; cout << d << dot << c << b << a; return 0;}*/#include<cstdio
2021-03-14 20:15:57
86
原创 第十五届浙江大学宁波理工学院程序设计大赛 - D Campaign
全部输入:4501 11 11 11 11 11 11 1501 120 3020 3020 301 120 3020 307019 1910 1010 1010 1010 1010 101 121 13 33 33 33 33 33 3我的错解:(只通过了50%的测试用例思路是算出可以占到的L有多少空间时, 同步计算R的空间, 再判断是否lose各用一个int变量记录,如果能占到空间的R小于总数,就lose如果能占到的L小于总...
2021-03-12 21:23:53
109
1
原创 第十五届浙江大学宁波理工学院程序设计大赛 - K Technology Tree
简单的前缀和for _ in range(int(input())): n, q = map(int, input().split()) lst = [] for i in range(n): lst.append(list(map(int, input().split()))) needs = list(map(lambda x: x-1, map(int, input().split()))) for idx, need in enumer...
2021-03-12 21:13:22
68
原创 leetcode 13. Roman to Integer
Roman to Integer写太长了舍不得删class Solution: def romanToInt(self, s: str) -> int: res = 0 i = 0 while i <= len(s) - 1: if s[i] == 'M': res += 1000 elif s[i] == 'D': re.
2021-03-12 09:43:08
32
原创 2021年度训练联盟热身训练赛第一场 F Pulling Their Weight
n = int(input())nums = []for _ in range(n): nums.append(int(input()))nums.sort()#print(nums)l = 0r = n-1l_sum = nums[l]r_sum = nums[r]while l + 1 < r: if l_sum < r_sum: l += 1 l_sum += nums[l] elif l_sum > ...
2021-03-11 19:00:48
177
原创 leetcode 258. Add Digits
class Solution: def addDigits(self, num: int) -> int: s = str(num) while len(s) > 1: d = 0 for i in range(len(s)): d += int(s[i]) s = str(d) return s
2021-03-11 11:26:10
110
原创 leetcode 976. Largest Perimeter Triangle
Largest Perimeter TriangleGiven an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.Example 1:Input: nums = [.
2021-03-11 11:16:31
73
原创 Codeforces Round #706 (Div. 2) A. Split it!
我的错解, 会溢出for _ in range(int(input())): n, k = map(int, input().split()) s = input() if k == 0: print('YES') else: if n % 2 == 0: i = 0 while s[n//2-i-1] != s[n//2+i]: i += 1 ..
2021-03-10 22:12:08
372
4
原创 codeforce contest/1462/problem/D 。Add to Neighbour and Remove
for _ in range(int(input())): n = int(input()) nums = tuple(map(int, input().split())) sum_nums = sum(nums) for i in range(n, 0, -1): nums_2 = list(nums) if sum_nums % i == 0: cnt = 0 ave = sum_nums..
2021-03-10 19:39:40
71
原创 codeforces contest/1462/problem/C. Unique Number
考虑到输入的数是输出的数每个位数的总和, 以及输出的数位数不能重复, 最多只能123456789各一个总和为45以及for _ in range(int(input())): n = int(input()) if n > 45: print(-1) elif n < 10: print(n) else: arr = [] i = 9 while n > 0: .
2021-03-10 19:17:44
61
原创 codeforces contest/1462/problem/B. Last Year‘s Substring
for _ in range(int(input())): n = int(input()) s = input() if s[:4] == '2020': print('YES') elif s[-4:] == '2020': print('YES') elif s[:1] + s[-3:] == '2020': print('YES') elif s[:2] + s[-2:] == '2020': ..
2021-03-10 18:38:45
71
原创 codeforces contest/1462/problem/A. Favorite Sequence
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = [] j = -1 if n % 2 == 1: for i in range(n // 2): ans.append(a[i]) ans.append(a[j]) j -= 1 ans..
2021-03-10 18:36:38
73
原创 C++入门同步记录#3
#include<iostream>using namespace std;int main() { int ans1; char ans2; ans1 = 'M' - 'A' + 1; ans2 = 33; cout << ans1 << endl; cout << ans2 << endl; return 0;}/*#include<iostream>#includ
2021-03-10 11:12:07
118
原创 C++入门同步记录#2
#include<iostream>#include<cmath>using namespace std;int main() { cout << sqrt(pow(6, 2) + pow(9, 2)) << endl; return 0;}#include<iostream>using namespace std;int main(){ int balance = 100; // 初始余额 bala
2021-03-10 09:43:09
138
原创 C++入门同步记录
#include<iostream>using namespace std;int main() { cout << "I Love Luogu!"; return 0;}#include<iostream>using namespace std;int main() { cout << 2 + 4 << " " << 10 - 2 - 4; return 0;}#in
2021-03-09 19:31:33
109
1
原创 西南民族大学第十二届程序设计竞赛 - G 阴阳怪气的宿舍
qh, sh, hl, xx, kt = input(), input(), input(), input(), input()def buhuiba(str): return str.count('buhuiba')def jiuzhe(str): return str.count('jiuzhe')qh_n = buhuiba(qh) + jiuzhe(qh)sh_n = buhuiba(sh) + jiuzhe(sh)hl_n = buhuiba(hl) + jiuzhe..
2021-03-09 19:17:38
106
原创 第十七届中国计量大学程序设计竞赛 - B Broken Pad
我的错解:for _ in range(int(input())): a = input() b = input() c = int(a)^int(b) start = 1 + len(str(a)) - len(str(c)) last = 0 lst = [] for idx, num in enumerate(str(c)): if num != last: lst.append(idx+start...
2021-03-08 19:19:27
87
原创 第十七届中国计量大学程序设计竞赛 - C Cook Steak
for _ in range(int(input())): times = int(input()) temper = 0 for i in range(times): l, r = map(int, input().split()) if temper > r: times = times + temper - r temper = r if temper < l: ...
2021-03-08 18:54:40
122
原创 leetcode 1009. Complement of Base 10 Integer
Complement of Base 10 IntegerEvery non-negative integer N has a binary representation. For example, 5 can be represented as “101” in binary, 11 as “1011” in binary, and so on. Note that except for N = 0, there are no leading zeroes in any binary repre.
2021-03-08 11:47:17
91
1
原创 leetcode 1103. Distribute Candies to People
Distribute Candies to PeopleWe distribute some number of candies, to a row of n = num_people people in the following way:We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person.The.
2021-03-08 10:53:17
72
原创 leetcode - 1025.Divisor Game
接受官方教育方法一 博弈找规律并证明class Solution: def divisorGame(self, N: int) -> bool: return False if N % 2 == 1 else True方法二 动态规划class Solution: def divisorGame(self, N: int) -> bool: f = [False, True] for i in range(2, N+..
2021-03-08 10:29:50
60
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人