#include<iostream> #include<vector> #include<algorithm> #include<string> usingnamespace std; structNode { int x; int y;
}; boolcmp(Node& a, Node& b){ if (a.x == b.x)return a.y > b.y; return a.x < b.x; } voidfunc(){ int n; cin >> n; vector<Node>nodes(n+1, Node{ 0,0 }); for (int i = 1; i <= n; i++) { cin >> nodes[i].x; } for (int i = 1; i <= n; i++) { cin >> nodes[i].y; }
sort(nodes.begin()+1, nodes.end(), cmp);
int sum = 0; vector<int>tails(n + 1, -1);//贪心数组 int end = 0; for (int i = 1; i <= n; i++) { if (tails[end] < nodes[i].y) { end++; tails[end] = nodes[i].y; } else { int l = 0; int r = end; while (l + 1 != r) { int mid = l + ((r - l) >> 1); if (tails[mid] >= nodes[i].y) { r = mid; } else l = mid; } tails[r] = nodes[i].y; } } cout << end << endl; } intmain() { int T; cin >> T; for (int j = 0; j < T; j++) { func(); } return0; }
x^n+y^n的值(阿里巴巴)
思路:(转自牛客)
这就是一道找规律的题目,还是很简单,但是提交上去死活过不了,因为取模有问题,这题中间可能有负数的情况,而题目的意思是结果取完模后不应该有负数,因此我们应该每次取模应该加上模数。(血的教训啊)dp[i] = ((A * dp[i - 1]) % M - (B * dp[i - 2]) % M + M) % M;这题观察动态转移方程组是可以缩减空间复杂度的降至O(1)