AcWing周赛 1
摘要:A:水题。 给定两个数组,找到从这俩数组中各找一数,使得和不在任何一个数组中。 因为数组中的数都是正整数,最大的俩数相加必然不在这俩数组之中。 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using name
阅读全文
leetcode周赛 242
摘要:A:水题,给定01串,问连续的0更长还是连续的1更长。 直接遍历即可。 1 class Solution { 2 public: 3 bool checkZeroOnes(string s) { 4 int res1=0,res0=0; 5 int cnt1=0,cnt0=0; 6 for(int
阅读全文
AcWing第二次热身赛
摘要:A:水题,找到不小于n的能够被4整除的最小的数。 假设n不能被4整除,那么n+1,n+2,n+3之中一定存在一个数能够被4整除。所以直接枚举即可。 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using na
阅读全文
leetcode周赛 241
摘要:A:水题,直接暴搜就好了。 1 class Solution { 2 public: 3 int res; 4 void dfs(vector<int>&nums,int i,int sum){ 5 if(i==nums.size()){ 6 res+=sum; 7 return ; 8 } 9 d
阅读全文
第十二届蓝桥杯C++ B组
摘要:A:计算256MB能够存放多少个int 1 int main() 2 { 3 cout<<256*1024*1024/4; 4 return 0; 5 } ans=67108864 B:计算2021张1到10的卡片能够拼出1~n的最大的n 1 int cnt[10]; 2 int main() 3
阅读全文
leetcode周赛 239
摘要:A:水题,直接枚举即可。 1 class Solution { 2 public: 3 int getMinDistance(vector<int>& nums, int target, int start) { 4 int res=0,seq=INT_MAX; 5 for(int i=0;i<nu
阅读全文
leetcode周赛 238
摘要:A:水题 1 class Solution { 2 public: 3 int sumBase(int n, int k) { 4 int res=0; 5 while(n){ 6 res+=n%k; 7 n/=k; 8 } 9 return res; 10 } 11 }; B:给定一个数组和一个可
阅读全文
Codeforces Round #713
摘要:又是该LL用int了,什么时候才能不犯病啊。 A:水题,让你找出3个以上的数组中不同的那个数 我是直接分情况。 1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 const int N=110; 5 int a[N];
阅读全文
leetcode周赛 233
摘要:A:水题,数据范围较小,直接暴力模拟。 1 class Solution { 2 public: 3 bool check(vector<int> a,int i,int j ){ 4 for(int k=i+1;k<=j;k++){ 5 if(a[k]<=a[k-1]){ 6 return fal
阅读全文
牛客 小白月赛32
摘要:A:枚举所有可能的情况,判断能否组成两个三角形。 1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 bool three_one(int a){ 5 int cnt0=0,cnt1=0; 6 for(int i=0;i<
阅读全文
leetcode周赛 232
摘要:A:水题,给定两个字符串,问能否只交换一次使得两字符串相等。 解法1:记录两字符串不相等的位置。 1 class Solution { 2 public: 3 bool areAlmostEqual(string s1, string s2) { 4 int n=s1.length(); 5 int
阅读全文
Codeforces Round #707
摘要:A:模拟题,每次进站加上应该要的时间和延迟的时间 每次等待的时候需要题给定的两个条件都满足。 注意:最后一站不需要等待,所以需要单独考虑。 1 #include<cstring> 2 #include<algorithm> 3 #include<iostream> 4 using namespace
阅读全文
Codeforces Round #706 A~C
摘要:A:给了一个比较复杂的定义,但是仔细读了之后就会发现问的就是字符串s的回文长度是否大于等于k,例如abqewba的回文长度是2. 1 #include<algorithm> 2 #include<iostream> 3 using namespace std; 4 5 int main(void){
阅读全文
leetcode周赛 231
摘要:A:水题。 解法1:首先确定一个全为1的串,之后如果在出现1,就返回false 1 class Solution { 2 public: 3 bool checkOnesSegment(string s) { 4 bool flag=true; 5 int n=s.size(); 6 for(int
阅读全文
Codeforces Round #702
摘要:A:给定一个序列,一个操作是向其中任何一个位置插入一个数,问至少需要多少次操作才能保证两两之间的max(a[i],a[i+1])/min(a[i],a[i+1])<=2。 假设在i和i+1之间插入一个数,这个操作并不会影响到其他,所以我们可以线性的考虑整个序列。 那么我们现在只需要考虑如果a和b,m
阅读全文
leetcode周赛 227
摘要:A:问能否将一个数组通过轮换的方式得到一个单调不减的数组。 因为范围只有100,直接将数组拷贝并排序,然后对原数组轮换n次,每次进行一下判断。 1 class Solution { 2 public: 3 bool check(vector<int>&a,vector<int>& b){ 4 int
阅读全文
leetcode双周赛 45
摘要:A:水题,求数组中只出现一次的元素的和。 1 class Solution { 2 public: 3 int sumOfUnique(vector<int>& nums) { 4 unordered_map<int,int> m; 5 for(auto x:nums){ 6 m[x]++; 7 }
阅读全文
leetcode周赛 226
摘要:A:模拟题,枚举每一个数,然后求出他应该放在哪一个盒子里面,时间复杂度为n*lgn 1 class Solution { 2 public: 3 int countBalls(int l, int r) { 4 vector<int> cnt(50,0); 5 int res=0; 6 for(in
阅读全文
Educational Codeforces Round 103
摘要:A:题意是给定n,k,求一个包含n个正整数的序列,满足序列和能够整除k,输出该序列最小的最大值。 如果n<=k,res等于k/n+(k%n != 0) 如果n>k,那么需要将k乘上一个数z,使得k>=n。而这个z=n/k+(n%k != 0),之后再进行上述操作。 1 #include<iostre
阅读全文
leetcode周赛 255
摘要:https://leetcode-cn.com/contest/weekly-contest-225/ A:枚举,或者可以找规律 解法一:枚举 1 class Solution { 2 public: 3 bool check(char * a,string& b){ 4 for(int i=0;i
阅读全文