后面的题目补不懂了
暴力 1001
这题也把我搞死了。。枚举系数判断就行了
#include#include #include #include #include
数学 1002
题意: 求|XA - XB| + |YA - YB| 最大
分析:去掉绝对值,就知道只要得到最大最小的(XA + XB) 和 (XA - XB)
#include#include #include #include #include #include #include using namespace std;long long seed;inline long long rand(long long l, long long r) { static long long mo=1e9+7, g=78125; return l+((seed*=g)%=mo)%(r-l+1);}const int N = 1e6 + 5;pair p[N];long long mx[2], mn[2];int main(void) { int T; cin >> T; while (T--) { int n; cin >> n >> seed; mx[0] = mx[1] = -(1ll << 60); mn[0] = mn[1] = (1ll << 60); for (int i = 0; i < n; i++) { p[i].first = rand (-1000000000, 1000000000); p[i].second = rand (-1000000000, 1000000000); mx[0] = max (mx[0], p[i].first + p[i].second); mx[1] = max (mx[1], p[i].first - p[i].second); mn[0] = min (mn[0], p[i].first + p[i].second); mn[1] = min (mn[1], p[i].first - p[i].second); } cout << max (abs (mx[0] - mn[0]), abs (mx[1] - mn[1])) << '\n'; } return 0;}
贪心 + BFS
题意:求位运算and的最大生成树
分析:枚举数字每一位是否有可能为1,即(now & w == now),用BFS遍历所有生成树
#include#include #include const int N = 3e5 + 5;struct Edge { int v, w;};std::vector G[N];int n, m;bool vis[N];bool BFS(int now) { std::queue que; memset (vis, false, sizeof (vis)); que.push (1); vis[1] = true; while (!que.empty ()) { int u = que.front (); que.pop (); for (int i=0; i =0; --i) { int now = ((1 << i) | ans); if (BFS (now)) ans = now; } printf ("%d\n", ans); } return 0;}