01 2022 档案
摘要:Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 48841 Accepted: 14278 Description There is an apple tree outside of kaka's house
阅读全文
摘要:Tunnel Warfare Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 10964 Accepted: 4538 Description During the War of Resistance Against Japan
阅读全文
摘要:输入两个整数 aa 和 bb,求 a^bab 的因子和。 由于结果太大,只要输出它对 99019901 取模的结果。 输入格式 仅一行,为两个整数 aa 和 bb。 输出格式 输出一行一个整数表示答案对 99019901 取模的结果。 输入输出样例 输入 #1复制 2 3 输出 #1复制 15 说明
阅读全文
摘要:1 class Solution { 2 public: 3 vector<int> sumOfDistancesInTree(int n, vector<vector<int>>& edges) { 4 vector<int>G[n],sz(n),sum(n); 5 for(auto &p:edg
阅读全文
摘要:描述 你玩过“拉灯”游戏吗?25盏灯排成一个5x5的方形。每一个灯都有一个开关,游戏者可以改变它的状态。每一步,游戏者可以改变某一个灯的状态。游戏者改变一个灯的状态会产生连锁反应:和这个灯上下左右相邻的灯也要相应地改变其状态。 我们用数字“1”表示一盏开着的灯,用数字“0”表示关着的灯。下面这种状态
阅读全文
摘要:描述 从 1~n 这 n 个整数中随机选出 m 个,输出所有可能的选择方案。n>0, 0<=m<=n, n+(n-m)<=25。 输入格式 两个整数n,m。 输出格式 按照从小到大的顺序输出所有方案,每行1个。 首先,同一行内的数升序排列,相邻两个数用一个空格隔开。其次,对于两个不同的行,对应下标的
阅读全文
摘要:描述 从 1~n 这 n(n<16) 个整数中随机选取任意多个,输出所有可能的选择方案。 输入格式 一个整数n。 输出格式 每行一种方案。同一行内的数必须升序排列,相邻两个数用恰好1个空格隔开。对于没有选任何数的方案,输出空行。本题有自定义校验器(SPJ),各行(不同方案)之间的顺序任意。 样例输入
阅读全文
摘要:背景 21 世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳。作为一名青春阳光好少年,atm 一直坚持与起床困难综合症作斗争。通过研究相关文献,他找到了该病的发病原因:在深邃的太平洋海底中,出现了一条名为 drd 的巨龙,它掌握着睡眠之精髓,能随意延长大家的睡眠时间
阅读全文
摘要:描述 求 a 乘 b 对 p 取模的值,其中 1≤a,b,p≤10^18。 输入格式 第一行a,第二行b,第三行p。 输出格式 一个整数,表示a*b mod p的值。 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long lo
阅读全文
摘要:描述 求 a 的 b 次方对 p 取模的值,其中 1≤a,b,p≤10^9 输入格式 三个用空格隔开的整数a,b和p。 输出格式 一个整数,表示a^b mod p的值。 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long l
阅读全文
摘要:描述 给定一张 n(n≤20) 个点的带权无向图,点从 0~n-1 标号,求起点 0 到终点 n-1 的最短Hamilton路径。 Hamilton路径的定义是从 0 到 n-1 不重不漏地经过每个点恰好一次。 输入格式 第一行一个整数n。 接下来n行每行n个整数,其中第i行第j个整数表示点i到j的
阅读全文
摘要:考虑如果顺序模拟会T,注意到最后一个元素一定在它确定的位置,考虑从后往前放,找第k个空位,完美解决这题; 1 #include<iostream> 2 #include<cstdio> 3 #define ls (x<<1) 4 #define rs (x<<1|1) 5 using namespa
阅读全文
摘要:1 class Solution { 2 public: 3 typedef long long ll; 4 const int lim=1e6; 5 int dx[8]={-1,0,1,0},dy[8]={0,1,0,-1}; 6 bool isEscapePossible(vector<vect
阅读全文
摘要:1 class Solution { 2 public: 3 vector<string>ans; 4 bool isAdditiveNumber(string num) { 5 int n=num.size(); 6 function<int(int,int)>dfs=[&](int u,int
阅读全文
摘要:P5490 【模板】扫描线 这题线段树的节点表示的是区间,树上节点x表示的区间【l,r】是实际点的[l,r+1]区间;因为我们纯用点一一对应 当标记落到一个点时 没有任何意义;标记更新,如果当前节点被标记,说明区间被标记,如果当前节点没被标记,返回左节点和右节点被标记的总长度 sum[x]维护的是节
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main() 5 { 6 string s; 7 cin>>s; 8 int ans=0,cnt=0; 9 for(auto &p:s) 10 { 11 if(p=='(')cnt++;
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 int n; 4 5 unordered_map<string,set<string>>mp; 6 vector<string>vec; 7 unordered_map<string,int>ch;
阅读全文
摘要:1 任选两颗A,B两颗种子,pa是种A种子需要的天数,ga是A种子开花需要的天数; 2 1.考虑先种A,后种B 3 mina_day=max(pa+ga,pa+pb+gb); 4 2.先种B,后种A; 5 minb_day=max(pb+gb,pb+pa+ga); 6 7 不妨设ga>gb; 8 p
阅读全文
摘要:1 class Solution { 2 public: 3 int minSwaps(vector<int>& nums) { 4 int n=nums.size(),sum1=0; 5 for(auto &p:nums)if(p)sum1++; 6 for(int i=0;i<n;i++)num
阅读全文
摘要:1 class Solution { 2 public: 3 int wordCount(vector<string>& startWords, vector<string>& targetWords) { 4 int n=startWords.size(),ans=0; 5 unordered_s
阅读全文
摘要:1 #include<bits/stdc++.h> 2 #define ls (x<<1) 3 #define rs (x<<1|1) 4 #define rep(i,a,b) for(int i=a;i<=b;i++) 5 #define pb(a) push_back(a) 6 using na
阅读全文
摘要:这题是线段树的区间加、区间修改和懒标记,注意开long long 1 #include<bits/stdc++.h> 2 #define ls (x<<1) 3 #define rs (x<<1|1) 4 #define rep(i,a,b) for(int i=a;i<=b;i++) 5 #def
阅读全文
摘要:1 int dp[11][11]; 2 int a[11]; 3 4 class Solution { 5 public: 6 long long dfs(int eq,int dep,int sum) 7 { 8 if(!dep)return sum; 9 if(~dp[dep][sum]&&!e
阅读全文
摘要:1 class Solution { 2 public: 3 vector<double> dicesProbability(int n) { 4 int dp[n+1][70]; 5 memset(dp,0,sizeof(dp)); 6 for(int i=1;i<=6;i++)dp[1][i]=
阅读全文
摘要:1 class Solution { 2 public: 3 int reversePairs(vector<int>& nums) { 4 int n=nums.size(); 5 int a[n+1]; 6 function<int(int,int)>merge=[&](int l,int r)
阅读全文
摘要:博弈论dp,记忆化搜索,从最开始的状态去搜; dp[mouse][cat][turn]表示当前mouse ,cat,turn三种状态下先手能获得的最优解,其中优先级赢>和>输; 1 class Solution { 2 public: 3 4 int catMouseGame(vector<vect
阅读全文
摘要:每次利用已经加入生成树的点集寻找未加入的点集的最小边,然后添加该点,并把minw[u]设置为最小生成树到u的最小距离; 证明算法正确性; 如果存在x1 x2均能联通到达生成树,其中若minw[x2]>minw[x1] 此时选x2加入生成树一定没有选X1优,正确性可以保证; 1 #include<bi
阅读全文
摘要:就是一种优化思想,基于搜索的思想,dijsktra堆优化也差不多是这样,只不过堆优化加了启发式选dis[u]较小的先更新,类似普通搜索与A*的区别;
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+5; 4 int dis[N],n,m; 5 struct edge 6 { 7 int u,v,w; 8 }e[N]; 9 //对每条边进行松弛,每次松弛至少能更新
阅读全文
摘要:1 class Solution { 2 public: 3 int maximumInvitations(vector<int>& favorite) { 4 int n=favorite.size(); 5 vector<int>ind(n); 6 for(int i=0;i<n;i++)ind
阅读全文