力扣 第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
阅读全文
Codeforces Round 993 (Div. 4)
摘要:https://codeforces.com/contest/2044 A. Easy Problem 签到题。对于大小为n的矩阵,有n-1个a>0&&b>0的(a,b)pair,满足b=n-a。 #include <iostream> #include <map> #include <string
阅读全文
蓝桥 小白入门赛24
摘要:https://www.lanqiao.cn/oj-contest/newbie-24/ 1. 分配辣条 签到题。 #include <iostream> using namespace std; int main() { cout<<20250601/305*305; return 0; } Vi
阅读全文
AcWing cup 2022春季
摘要:A:水题。 链接:https://www.acwing.com/problem/content/4379/ 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <map> 5 using names
阅读全文
AcWing周赛 40
摘要:A:签到题,直接模拟即可 题目地址:https://www.acwing.com/problem/content/4308/ 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <set> 5 6
阅读全文
Codeforces Round #739
摘要:A:水题,预处理一下符合题目要求的数即可。 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include<queue> 5 #include<unordered_map> 6 using namespace
阅读全文
leetcode周赛 248
摘要:A:模拟题。 1 class Solution { 2 public: 3 vector<int> buildArray(vector<int>& nums) { 4 int n=nums.size(); 5 vector<int> ans(n); 6 for(int i=0;i<n;i++){ 7
阅读全文
AcWing周赛 6
摘要:A:水题。 https://www.acwing.com/problem/content/3736/ 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 const in
阅读全文
AcWing周赛 5
摘要:A:水题。 https://www.acwing.com/problem/content/3729/ 1 #include<iostream> 2 using namespace std; 3 const int N=110; 4 int w[N]; 5 int main() 6 { 7 int T
阅读全文
数据结构--线段树
摘要:线段树的基本思想是分治。 此处的是简单线段树,即只支持单点修改,区间查询,不涉及懒标记。 树的每一个节点维护一个区间 [ l , r ] 的值,其子节点的区间的并集等于这个区间的值,左儿子维护[l , mid] ,右儿子维护[ mid+1 , r ]。 树的高度为log(n),所以更新操作的时间复杂
阅读全文
leetcode周赛 243
摘要:A:水题。 https://leetcode-cn.com/problems/check-if-word-equals-summation-of-two-words/ 1 class Solution { 2 public: 3 int tans(string s){ 4 int res=0; 5
阅读全文
AcWing周赛 1
摘要:A:水题。 给定两个数组,找到从这俩数组中各找一数,使得和不在任何一个数组中。 因为数组中的数都是正整数,最大的俩数相加必然不在这俩数组之中。 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using name
阅读全文