Given ${n}$ points in 2D plane. Considering all circles that the origin point ${(0, 0)}$ is on their boundries, find the one with the maximum given points on its boundry. Print the maximum number of points.
//map<node,int> M; int n; node mem[4000000]; intmain(){ scanf("%d",&n); for(int i=1; i<=n; i++)scanf("%lf%lf",&a[i].x,&a[i].y); if(n==1) { puts("1"); return0; } int memcnt = 0; for(int i=1; i<=n; i++) for(int j=i+1; j<=n; j++) { double r=0; Point tmp=tcircle(a[i],a[j],Point(0,0),r); if(r==-1)continue; node tmpp=node(tmp.x,tmp.y,r); mem[memcnt++] = tmpp; //M[tmpp]++; } sort(mem,mem+memcnt); int curcnt = 0; int st = 0; int ans = 1; node x; for (int i=0;i<memcnt;i++) { if (i == 0) { curcnt = 1; } else { bool eq = !(mem[i] < mem[i-1]) && !(mem[i-1] < mem[i]); if (eq) { curcnt ++; } else { if (curcnt > ans) { ans = curcnt; x = mem[st]; } curcnt = 1; st = i; } } } if (curcnt > ans) { ans = curcnt; x = mem[st]; } if(ans==1)printf("%d\n",ans); else { int cnt=0; for(int i=1; i<=n; i++)if(dcmp((a[i].x-x.x)*(a[i].x-x.x)+(a[i].y-x.y)*(a[i].y-x.y),x.r*x.r)==0)cnt++; printf("%d\n",cnt); } return0; }
C.Cover the Tree
题目描述
Given an unrooted tree, you should choose the minimum number of chains that all edges in the tree are covered by at least one chain. Print the minimum number and one solution. If there are multiple solutions, print any of them.
#include<bits/stdc++.h> usingnamespacestd; intread(){ int res = 0; char c = getchar(); while (!(c >= '0' && c <= '9')) c = getchar(); while (c >= '0' && c <= '9') { res = res*10 + c - '0'; c = getchar(); } return res; } intgettime(){ int h = read(); int m = read(); int s = read(); m += h * 60; s += m * 60; return s; } intmain(){ printf("%d\n",abs(gettime() - gettime())); return0; }
F.Fake Maxpooling
题目描述
Given a matrix of size $n\times m$ and an integer ${k}$, where $A_{i,j} = lcm(i, j)$, the least common multiple of ${i}$ and ${j}$. You should determine the sum of the maximums among all $k\times k$ submatrices.
#include<iostream> #include<cstdio> #include<algorithm> #include<deque> usingnamespacestd; constint N = 5e3 + 5; int t[N][N]; int ans[N][N]; deque<int> win(N);
// 标准的滑动窗口 voidsolve1(int n, int len, int *arr, int *ans){ win.clear(); for(int i = 0; i < n; i ++) { while(!win.empty() && arr[win.back()] < arr[i]) win.pop_back(); while(!win.empty() && win.front() < i - len + 1) win.pop_front(); win.push_back(i); if(i + 1 >= len) ans[i - len + 1] = arr[win.front()]; } }
intmain(){ ios::sync_with_stdio(false); int m, n, a, b, k; cin >> n >> m >> k; a=k;b=k; for(int i = 0; i < m; i ++) for(int j = 0; j < n; j ++) t[i][j]=(i+1)/__gcd(i+1,j+1)*(j+1); for(int i = 0; i < m; i ++) solve1(n, b, t[i], ans[i]);
// 遍历每列 // 第二次用作滑动窗口的数组是经过第一次处理后的 int len = a; for(int i = 0; i < n; i ++) { win.clear(); for(int j = 0; j < m; j ++) { while(!win.empty() && ans[win.back()][i] < ans[j][i]) win.pop_back(); while(!win.empty() && win.front() < j - len + 1) win.pop_front(); win.push_back(j); if(j + 1 >= len) ans[j - len + 1][i] = ans[win.front()][i]; } }
longlong sum=0;
for(int i = 0; i < m - a + 1; i ++) for(int j = 0; j < n - b + 1; j ++)sum+=ans[i][j]; printf("%lld\n",sum); return0; }
I.Interval
题目描述
There is an interval ${[1, n]}$ initially. For an interval ${[l, r]}$, if ${l < r}$, there will be two possible changes:
Shrinking, ${[l, r]}$ changes to ${[l + 1, r]}$ or ${[l, r - 1]}$
Expanding, ${[l, r]}$ changes to ${[l - 1, r]~(l > 1)}$ or ${[l, r + 1]~(r < n)}$
So, when ${l = r}$, the interval will be unable to be changed. You don’t want to see this, so you may need to ban some changing manners. Specifically, we use tuple ${(l, r, dir, c)}$ to describe banning. If ${dir = L}$, you can ban the bidirectional changing between ${[l, r]}$ and ${[l + 1, r]}$ with cost ${c}$ while you can ban the bidirectional changing between ${[l, r]}$ and ${[l, r - 1]}$ with cost ${c}$ if ${dir = R}$. Determine the minimum total cost to guarantee that ${l = r}$ will never happen. Print “-1” if it’s impossible to make it.
Given a permutation with size ${n}$ and an integer ${k}$, you should find a permutation substitution ${P}$ that $\{1, 2, \cdots, n\}$ will become ${A}$ after performing substitution ${P}$ for exactly ${k}$ times. Print the permutation after performing ${P}$ for once on $\{1, 2, \cdots, n\}$. If there are multiple solutions, print any of them. If there is no solution, print “-1” in one line.