随笔分类 - 模拟
基础算法
摘要:链接:https://leetcode-cn.com/problems/my-calendar-i/ 729. 我的日程安排表 I 题意:给出多个区间,查询某个区间是否与其前的区间相交 思路:维护pair排序后序列,对于输入区间二分到可能相交的区间进行判断,时间复杂度为O(NlogN),参考网络题解
阅读全文
摘要:第一题:https://leetcode-cn.com/problems/determine-whether-matrix-can-be-obtained-by-rotation/ 1886. 判断矩阵经轮转后是否一致 思路:90度顺时针旋转后,(i,j)->(j,n-i-1),分别计算旋转得到的四
阅读全文
摘要:链接:https://www.acwing.com/problem/content/3419/ 代码: #include<bits/stdc++.h> #define intl long long using namespace std; int main (){ intl num; cin>>nu
阅读全文
摘要:链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805081289900032 思路:首先理解清楚题意:给队员分座位,保证同一个学校的队员不挨着,如果前一个座位的同学是自己学校的,那么隔一个去坐(意思等同于文中,最后剩
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T51 代码: #include<bits/stdc++.h> using namespace std; int check(int x){ int a=x-3500; int ans=0; ans+=max(0,min
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T52 代码: #include<bits/stdc++.h> using namespace std; map<int,int>mp; int main (){ int n,num; cin>>n; for(int i
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T46 思路:模拟,用20个数组标记这100个座位,分别对连续和不能连续购买座位进行枚举输出。 代码: #include<bits/stdc++.h> using namespace std; int a[25]; in
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T47 代码: #include<bits/stdc++.h> using namespace std; int main (){ int n,num,ans=0; vector<int>ve; cin>>n; for(
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T41 思路:有点坑的大模拟,模拟俄罗斯方块下落的过程,从上到下依次拿小矩形最左边的点去枚举判断,找到当前行可以下落的最低位置后输出 代码: #include<bits/stdc++.h> using namespace
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T42 代码: #include<bits/stdc++.h> using namespace std; vector<int> ve; int main (){ int n,num; cin>>n; for(int i
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T36 注意事项:纵向遍历时注意; 思路: 思路1:把有能够消除的坐标进行加入map标记,这样横纵消除互不影响; 思路2:把能够消除的坐标值标为负数,这样横纵不影响对比,输出也方便判断。 代码: #include<bit
阅读全文
摘要:链接:https://ac.nowcoder.com/acm/contest/12800/G 思路: 输入num 1 2 3 4 5 6 7 8………………num 1 3 5 7 9 11 13………………2num-1 1 4 9 16 25 36 49………………numnum 1 2 4 8 16
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T31 注意:闰年的判断条件:1:年份是4的整数倍,而且不是100的整数倍;2:年份是400的整数倍。两个条件满足之一即可 平年:2月28天,闰年:2月29天 代码: #include<bits/stdc++.h> us
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T32 代码: #include<bits/stdc++.h> using namespace std; int main (){ int n; cin>>n; int num,atm=-1,ans=0; for(int
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T26 参考了网络上的代码:对于1:vector的使用有了新的反思,2:以及tie用于排序。 //具体学到什么,待补充:~~~ 代码: #include<bits/stdc++.h> using namespace st
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T27 代码: 通过vector来实现二维数组的方法,参考别人思路,此处无链接~ #include<bits/stdc++.h> using namespace std; int main (){ ios::sync_w
阅读全文
摘要:题目链接:http://118.190.20.162/view.page?gpid=T88 反思:不管是queue.front() 还是queue.back()都可以直接修改队头和队尾的值,不用弹出后计算完再加入。 代码: #include<bits/stdc++.h> using namespac
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T15 代码: map: #include<bits/stdc++.h> using namespace std; map<pair<int,int>,int>mp; int main (){ ios::sync_wit
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T9 思路: 增加一个数组来记录当前的窗口从上到下依次是多少,如果有点击,则把点击的窗口移动到最上边(通过相邻的swap来移动达到维护目的) 代码: #include<bits/stdc++.h> using names
阅读全文
摘要:链接:http://118.190.20.162/view.page?gpid=T10 代码: #include<bits/stdc++.h> using namespace std; unordered_map<int,int>mp; int main (){ int n,num,ans=0; c
阅读全文