摘要:
题目链接 A. Cubes Sorting 思路: 根据可交换的次数可以看出:直接判断数组是否是递减的即可。 代码: const int N = 1e5 + 10; int a[N]; int main(){ int t; cin >> t; while(t --){ int n; cin >> n 阅读全文
摘要:
Anu Has a Function 思路: \(f(x, y) = x | y - y\)。将 \(x, y\) 对齐。那么结果就是:如果 \(y\) 的第 \(i\) 是 $1$,那么把 \(x\) 的第 \(i\) 位变为 $0$(无论之前是什么)。那么根据这个性质可以发现,改变的都是第 $1 阅读全文
摘要:
1. 两数之和 思路: 暴力遍历 代码: class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { int lenNums = nums.size(); int a, b; for(int i = 0; 阅读全文
摘要:
题目链接 A - Decrease the Sum of Digits 思路: 记录以下到那个位置会大于 \(s\),然后前一个位置的数加一,之后的全部变为零即可。 注意特判到某个位置刚好等于 \(s\) 的情况。 代码: int main(){ int t; cin >> t; while(t - 阅读全文