合集-记录随手刷过的编程题
摘要:This is a programing problem on codefores with a difficulty score of 1400. It presents an intresting challenge that can be solved using the principle
阅读全文
摘要:This is a chanllenging problem on codeforces with a diffcuilt score of 1400. It presents a intressting chanllege that can be solved by using the princ
阅读全文
摘要:https://codeforces.com/problemset/problem/1369/C This is a hard problem on codefores with a diffcuilty score of 1400 It can also be solved by using th
阅读全文
摘要:https://codeforces.com/problemset/problem/550/B Brute force problem void solve(){ int n, l, r, x; cin >> n >> l >> r >> x; vector<int> a(n); for(auto&
阅读全文
摘要:This a constructive problem on codeforces with a diffcuilty score of 1400. https://codeforces.com/problemset/problem/1463/B It's evident that we can a
阅读全文
摘要:https://codeforces.com/problemset/problem/1490/E This is a chanllenging problem on codeforces with a diffcuilty score of 1400. It can be solved by usi
阅读全文
摘要:https://codeforces.com/problemset/problem/277/A It presents a problem that we need to make all element connected, it can be solved by using dsu. I did
阅读全文
摘要:https://codeforces.com/problemset/problem/762/A This is a easy problem based on number theory. We just simply iterate i from 1 to the value of sqrt(n)
阅读全文
摘要:It's a simple problem on codeforces. we traverse the through the string n, if we encouter a '1', we add a new string to ans and set stop to false.Othe
阅读全文
摘要:这是一个dp题,可以用4维数据来表示所有的状态。 但是有一个需要注意的点,一般来说,对于每个坐标,有拿跟不拿两种情况,如果没有拿任务宝物的状态表示为0,那么拿取了价值为0的宝物时,要以另一种情况来跟没拿区分。 处理的方法就是将所有宝物的价格+1。 long long dp[55][55][15][1
阅读全文
摘要:https://codeforces.com/contest/977/problem/D void solve(){ int n; cin >> n; vector<pair<int, long long>> a(n); for (auto&[x, y] : a){ cin >> y; x = 0;
阅读全文
摘要:https://codeforces.com/problemset/problem/1355/D We have a constructive problem where we need to construce an array with a required sum value using n
阅读全文
摘要:https://codeforces.com/problemset/problem/1332/B void solve(){ int n; cin >> n; vector<vector<int>> ans(1234); for (int i = 0; i < n; ++i){ int t; cin
阅读全文
摘要:题意:给定n个区间,左端点和右端点表示工作开始时间和结束时间。求最长一直有人在工作的时间和无人工作的时间。 思路:想到了并查集,还有差分树状数组,最后选择差分数组。左端点加,右端点减,然后一次遍历即可。 总结:习惯性的在右端点+1的位置减少了1,但是不适用于这个题目的逻辑。 因为在右端点+1的位置修
阅读全文
摘要:题意:给定一个宽度w,n个数,每个数有一个权值。窗口可以变换位置,求该窗口能容纳的最大权值。 思路:前缀和+滑动窗口硬算。 总结:一开始感觉是fenwicktree,但是每次查询的区间固定,不需要fenwicktree,不如滑动窗口来的方便。 void solve(){ int n, w; cin
阅读全文
摘要:https://www.luogu.com.cn/problem/P8818 什么玩意儿。。这种策略题不就是你来我往的,你如果选那个我就选这个,到了最后俩人都做不了决策,一直在博弈吗 放个示例跑不过去的代码 真不想调,这种题就是恶心啊,你说说怎么调呢 针对一方的选择,另一方总能选出更优的策略来。然后
阅读全文
摘要:A. Painting the Ribbon 题意:n个物体,m个颜色,alice要给每个物体任意涂一个颜色。bob可以给k个物体涂色 ,问alice能否阻止bob让所有的物体颜色都相同。 思路:思维题。如果m=1,那么无解。如果m > 1,那么bob如果想要染成同一个颜色,alice可以让bob需
阅读全文
摘要:https://codeforces.com/contest/1954/problem/E 题意:n个数,可以对每个数释放闪电,闪电从释放的位置一直传到左右边界或者传到某个小于等于0的数终止,并且每个数都会减去闪电值k。问最少多少次释放闪电后可以让所有的数小于等于0。 思路:从左往右考虑,假设第一个
阅读全文
摘要:题意:给一个树和一个bfs序,并保证从节点1出发,判bfs序是否合法。 思路:双指针,在bfs序上从左往右遍历。慢指针指向当前节点u,快指针指向当前节点应该访问的节点的位置。 然后设两个集合,一个集合存储在当前节点上应该访问的节点,另一个存储在当前节点上实际访问的节点,然后遍历即可。 总结:一开始想
阅读全文
摘要:https://codeforces.com/problemset/problem/161/D 题意:给一棵树,求树上距离为k的节点对的数量。 思路:树上dp,随便找个节点开始遍历。然后枚举当前点的距离为i的节点数与当前点的孩子节点距离为k - i - 1的节点数相乘。 总结:想到了树上dp,也想到
阅读全文