力扣 第178场双周赛(A~C)
摘要:A:3866. 找到第一个唯一偶数题意见题目即可,cnt数一下,然后判数目就行。 1 class Solution { 2 public: 3 int firstUniqueEven(vector<int>& nums) { 4 int n=nums.size(); 5 map<int,int> c
阅读全文
力扣 第492场周赛(A~D)
摘要:A:101010. 容量最小的箱子 简单题,遍历即可。 1 class Solution { 2 public: 3 int minimumIndex(vector<int>& ca, int it) { 4 int min_c=INT_MAX; 5 int id=-1; 6 for(int i=0
阅读全文
力扣 第491场周赛(A~D)
摘要:A:3856. 移除尾部元音字母 简单题。 1 class Solution { 2 public: 3 string trimTrailingVowels(string s) { 4 set<char> S={'a','e','i','o','u'}; 5 while(s.size()&&S.co
阅读全文
力扣 第177场双周赛(A~D)
摘要:A:3852. 不同频率的最小数对给定一个数组,要求这个数组中频率不同的最小的两个数。 这个数组中的min是必选的,可由反证法证。假设ans=[a,b],二者都不为min,且freq(a)!=freq(b),那么一定可以将其中一个数替换为min,同样满足频率不同。 必须min,那么O(n)找另一个数
阅读全文
力扣 第488场周赛(A~D)
摘要:A:3833. 统计主导元素下标数 算一下sum,然后一边遍历一边减即可判断当前元素是否是主导元素。 1 class Solution { 2 public: 3 int dominantIndices(vector<int>& nums) { 4 int sum=accumulate(nums.b
阅读全文
力扣 第 476 场周赛(A~D)
摘要:A:3745. 三元素表达式的最大值签到题,直接排序,首尾分别取两个和一个就可以了。 1 class Solution { 2 public: 3 int maximizeExpressionOfThree(vector<int>& nums) { 4 sort(nums.begin(),nums.
阅读全文
力扣 第 169 场双周赛(A~D)
摘要:A:3736. 最小操作次数使数组元素相等 III签到题。 1 class Solution: 2 def minMoves(self, nums: List[int]) -> int: 3 return max(nums)*len(nums)-sum(nums) B:3737. 统计主要元素子数组
阅读全文
力扣 第 475 场周赛(A~C)
摘要:A:3740. 三个相等元素之间的最小距离 I见B。 B:3741. 三个相等元素之间的最小距离 II 给定数组nums,要求值相同的三元组的下标最小距离,距离定义为abs(i - j) + abs(j - k) + abs(k - i),数据范围为1e5. 我们我们可以按[值,下标]升序排序,然后
阅读全文
AtCoder Beginner Contest 430 (A~E)
摘要:A:Candy Cookie Law 签到题。 1 a,b,c,d = map(int,input().split()) 2 if c>=a: 3 if d>=b: 4 print("No") 5 else: 6 print("Yes") 7 else: 8 print("No") B:Count
阅读全文
力扣 第474场周赛
摘要:Q1. 找出缺失的元素签到题,排序之后一个一个找就行。 1 class Solution { 2 public: 3 vector<int> findMissingElements(vector<int>& nums) { 4 sort(nums.begin(),nums.end()); 5 vec
阅读全文
力扣 第471场周赛(A~D)
摘要:A:出现次数能被 K 整除的元素总和 签到题,给一个整数数组nums和一个数k,计算nums中出现次数能被k整除的数之和。 解法,做一个cnt,再遍历一遍就行了。 1 class Solution: 2 def sumDivisibleByK(self, nums: List[int], k: in
阅读全文
力扣 第455场周赛(A~C)
摘要:A.检查元素频次是否为质数 签到题。 1 class Solution { 2 public: 3 bool isprime(int x){ 4 if(x<=1) return false; 5 for(int i=2;i<=x/i;i++){ 6 if(x%i==0) 7 return false
阅读全文
力扣 第159场双周赛(A~C)
摘要:A.最小相邻交换至奇偶交替 给一个数组,一次操作能够将相邻两个元素互换,问最少多少次操作之后,能够使得数组奇偶相间。 首先我们考虑我们的目标序列该是什么样子,当我们在某个位置需要一个特定的奇数或者偶数时,我们肯定是拿最近的来填,所以我们按顺序将数组分成奇偶两个,然后从这两个数组中一边拿一个就构成了我
阅读全文
牛客练习赛141
摘要:A.小柒与啦啦啦的博弈 签到题,从大到小排序后,按顺序依次拿就可以了。 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 typedef long long LL; 5 const int N = 1e6+10;
阅读全文
牛客小白月赛118(A~D)
摘要:A.红橙 签到题。 1 #include <iostream> 2 using namespace std; 3 int main(){ 4 int x,y; 5 cin>>x>>y; 6 if(x==y) cout<<"Draw"<<endl; 7 else if(y==(x+1)%3) cout
阅读全文
Codeforces Round 1030 (Div. 2)(A~C)
摘要:A.Equal Subsequences 给定n,k,要求构造出一个只包含0和1的字符串,且字符串中101子序列和010子序列有相同的个数。 那么11111101000000,即取出01,然后左边有多少个1,就有多少个101子序列,右边有多少个0,就有多少个010子序列,那么再将多余的0和1放入字符
阅读全文
牛客练习赛140(A~C)
摘要:A-袋鼠将军的密码 签到题。 1 #include <iostream> 2 using namespace std; 3 /* run this program using the console pauser or add your own getch, system("pause") or i
阅读全文
Codeforeces Round 1029 (Div 3)(A~D)
摘要:A. False Alarm 只有当遇到关着的门才需要使用能力,标记最左侧关着的门为l,最右侧的关着的门为r,那么如果r-l+1>x则不能通过。 1 #include <iostream> 2 using namespace std; 3 /* run this program using the
阅读全文
leetcode 周赛 442
摘要:A:船上可以装载的最大集装箱数量 简单题,直接取min就可以了。 1 class Solution { 2 public: 3 int maxContainers(int n, int w, int maxWeight) { 4 return min(n*n, maxWeight/w); 5 } 6
阅读全文
leetcode 周赛 439
摘要:1、模拟题 1 class Solution { 2 public: 3 int largestInteger(vector<int>& nums, int k) { 4 int n=nums.size(); 5 map<int,int> mp; 6 for(int i=0;i+k<=n;i++){
阅读全文