classSolution { public: intBuyPencils(int n, vector<vector<int> > & pencils){ int ans = 0x7FFFFFFF; for (int i = 0; i < 3; ++i) { // 数量、价格 int x = pencils[i][0], y = pencils[i][1]; ans = min(ans, (n / x + (n % x > 0 ? 1 : 0)) * y); } return ans; } };
intmain(){ int n; vector<vector<int> > pencils(3, vector<int>(2, 0)); cin >> n; for (int i = 0; i < 3; ++i){ cin >> pencils[i][0] >> pencils[i][1]; } Solution s; cout << s.BuyPencils(n, pencils); return0; }
publicintBuyPencils(int n, int[][] pencils) { intans= Integer.MAX_VALUE; for (int[] p : pencils) { intnum= p[0], prices = p[1]; ans = Math.min(ans, (prices * (n / num + (n % num == 0 ? 0 : 1)))); } return ans; } }
1 2 3 4 5 6
n = int(input()) pencils = [] for _ inrange(3): pencils.append(map(int, input().split())) ans = min(b * (n // a + (1if n % a else0)) for a, b in pencils) print(ans)
classSolution { public: intJinjinplan(vector<int>& nums){ int n = nums.size(); // 12 int pre = 0, s = 0; // 上个月剩下的零钱, 存下的零钱 for (int i = 0; i < n; ++i) { int cur = pre + 300 - nums[i]; // 本月除去预算剩下的 if (cur < 0) return -(i + 1); pre = cur % 100; s += cur - pre; } returnint(s * 1.2) + pre; } };
intmain(){ vector<int> nums(12, 0); for (int i = 0; i < 12; ++i) { cin >> nums[i]; } Solution s; cout << s.Jinjinplan(nums); return0; }
publicintJinjinplan(int[] nums) { intn= nums.length; // 12 intpre=0, s = 0; // 上个月剩下的和存在妈妈那里的 for (inti=0; i < n; ++i) { intcur=300 + pre - nums[i]; if (cur < 0) return -(i + 1); // 不够花了 pre = cur % 100; s += cur - pre; } return (int)((double)s * 1.2) + pre; } }
1 2 3 4 5 6 7 8 9 10 11 12
classSolution: defJinjinplan(self, nums): pre, s = 0, 0 for i, m inenumerate(nums): cur = 300 + pre - m if cur < 0: return -(i + 1) pre = cur % 100 s += cur - pre returnint(s * 1.2) + pre
nums = [int(input()) for _ inrange(12)] print(Solution().Jinjinplan(nums))
classSolution { public: intUnhappyJinjin(vector<int>& nums){ int data = 0, tim = -1; for (int i = 0; i < 7; ++i) { if (nums[i] > 8 && nums[i] > tim) { data = i + 1; tim = nums[i]; } } return data; } };
intmain(){ vector<int> nums(7, 0); for (int i = 0; i < 7; ++i) { int a, b; cin >> a >> b; nums[i] = a + b; } Solution s; cout << s.UnhappyJinjin(nums) << endl; return0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import Java.util.*; publicclassMain { publicstaticvoidmain(String[] args) { Scannersc=newScanner(System.in); intdata=0, tim = -1; for (inti=0; i < 7; ++i) { ints= sc.nextInt() + sc.nextInt(); if (s > 8 && s > tim) { data = i + 1; tim = s; } } System.out.println(data); sc.close(); } }
1 2
nums = [sum(map(int, input().split())) for _ inrange(7)] print(max([i for i inrange(7) if nums[i] > 8], key=lambda x: nums[x]) + 1)
classSolution { public: intCountProblem(int n, int x){ int cnt = 0; for (int i = 1; i <= n; ++i) { int s = i; while (s > 0) { if (s % 10 == x) ++cnt; s /= 10; } } return cnt; } };
intmain(){ Solution s; int n, x; cin >> n >> x; cout << s.CountProblem(n, x) << endl; return0; }
classSolution { public: string Cantor(int n){ // 根据等差数列求和公式 (1 + i) * i / 2 = n 反推 n 所在行号 i int i = (int)ceil(sqrt(2 * (double)n + 0.25) - 0.5); int s = n - (i - 1) * i / 2; // 计算行内的具体位置 if (i % 2 == 0) { // 偶数行逆序 s = i + 1 - s; } returnto_string(i + 1 - s) + "/" + to_string(s); } };
public String Cantor(int n) { // 根据等差数列求和公式 (1 + i) * i / 2 = n 反推 n 所在行号 i inti= (int)Math.ceil(Math.sqrt(2 * (double)n +0.25) - 0.5); ints= n - (i - 1) * i / 2; // 计算行内的具体位置 if (i % 2 == 0) { // 偶数行逆序 s = i + 1 - s; } return Integer.toString(i + 1 - s) + "/" + Integer.toString(s); } }
1 2 3 4 5 6 7 8
import math n = int(input()) # 根据等差数列求和公式 (1 + i) * i / 2 = n 反推 n 所在行号 i i = math.ceil(math.sqrt(2 * n + 0.25) - 0.5) s = n - (i - 1) * i // 2# 计算行内的具体位置 if i % 2 == 0: s = i - s + 1 print("{}/{}".format(i + 1 - s, s))