[杂题] Codechef SnackDown 2017 Onsite Final #MINIMAX Minimax

版权声明:本文为博主原创文章,未经博主允许随意转载。 https://blog.csdn.net/u014609452/article/details/75907167

最小值的最大值小于等于最大值的最小值
那么只要有一行一列最小值等于最大值,那么矩阵就合法
如果我们枚举这一行和这一列,那么最小值最大值一定就是他们的交点
那么再枚举交点最后的值是多少
这样复杂度是O(n4)
换一下 先枚举值 再枚举位置 可以去一个代价最小值
O(n2logn)

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
using namespace std;
typedef pair<int,int> abcd;

#define read(x) scanf("%d",&(x))

const int N=1005;

int n,a[N][N];

abcd b[N*N];

multiset<int> Set;

int rm[N*N],cm[N*N];
int cnt[N];

inline void add(int x){
  Set.erase(Set.find(cnt[x])); cnt[x]++; Set.insert(cnt[x]);
}

int main(){
  freopen("t.in","r",stdin);
  freopen("t.out","w",stdout);
  read(n);
  for (int i=0;i<n;i++) for (int j=0;j<n;j++) read(a[i][j]),b[i*n+j]=abcd(a[i][j],i*n+j);
  sort(b,b+n*n);
  rm[0]=0;
  for (int i=0;i<n;i++) cnt[i]=0,Set.insert(0);
  for (int i=0,j;i<n*n;i=j+1){
    j=i,add(b[j].second/n);
    while (j+1<=n*n && b[j+1].first==b[i].first)
      j++,add(b[j].second/n);
    rm[j+1]=*(Set.begin());
  }
  Set.clear();
  for (int i=0;i<n;i++) cnt[i]=0,Set.insert(0);
  cm[n*n-1]=0;
  for (int i=n*n-1,j;~i;i=j-1){
    j=i,add(b[j].second%n);
    while (j-1>=0 && b[j-1].first==b[i].first)
      j--,add(b[j].second%n);
    cm[j-1]=*(Set.begin());
  }
  int ans=1<<30;
  for (int i=0,j;i<n*n;i=j+1){
    j=i; while (j+1<n*n && b[i].first==b[j+1].first) j++;
    ans=min(ans,rm[i]+cm[j]);
  }
  printf("%d\n",ans);
  return 0;
}
阅读更多

Minimax Triangulation

06-28

Problem DescriptionnTriangulation of surfaces has applications in the Finite Element Method of solid mechanics. The objective is to estimate the stress and strain on complex objects by partitioning them into small simple objects which are considered incompressible. It is convenient to approximate a plane surface with a simple polygon, i.e., a piecewise-linear, closed curve in the plane on m distinct vertices, which does not intersect itself. A chord is a line segment between two non-adjacent vertices of the polygon which lies entirely inside the polygon, so in particular, the endpoints of the chord are the only points of the chord that touch the boundary of the polygon. A triangulation of the polygon, is any choice of m - 3 chords, such that the polygon is divided into triangles. In a triangulation, no two of the chosen chords intersect each other, except at endpoints, and all of the remaining (unchosen) chords cross at least one of the chosen chords. Fortunately, finding an arbitrary triangulation is a fairly easy task, but what if you were asked to find the best triangulation according to some measure?nnnnFigure I.1: Five out of nine possible triangulations of the example polygon. The leftmost hasnthe smallest largest triangle.n nnInputnOn the first line of the input is a single positive integer n, telling the number of test scenarios to follow. Each scenario begins with a line containing one positive integer 2 < m < 50, being the number of vertices of the simple polygon. The following m lines contain the vertices of the polygon in the order they appear along the border, going either clockwise or counter clockwise, starting at an arbitrary vertex. Each vertex is described by a pair of integers x y obeying 0 <= x <= 10 000 and 0 <= y <= 10 000.n nnOutputnFor each scenario, output one line containing the area of the largest triangle in the triangulation of the polygon which has the smallest largest triangle. The area should be presented with one fractional decimal digit.n nnSample Inputn1n6n7 0n6 2n9 5n3 5n0 3n1 1n nnSample Outputn9.0n n

没有更多推荐了,返回首页