1.Splitting the Field

http://usaco.org/index.php?page=viewproblem2&cpid=645

给二维坐标系中的n个点,求ans=用一个矩形覆盖所有点所用矩形面积-用两个矩形覆盖所有点所用两个矩形的最小面积和,而且两个矩形不能重合(边重合也不行)

枚举两个矩形的分割线,也就是把所有点分成两个部分,枚举分割点;先预处理每个点之前和之后的最大,最低高度

#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 50015
#define down(i,r,l) for(int i=r;i>=l;i--)
#define rep(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
int l[N],r[N],l1[N],r1[N],n;
ll zs,ans;
struct node{int x,y;}s[N];
bool cmp(node x,node y) {return x.x==y.x?x.y<y.y:x.x<y.x;}
void getans() {
ll now;
sort(s+,s++n,cmp);
memset(l,,(n+)<<); memset(l1,,(n+)<<); memset(r,,(n+)<<); memset(r1,,(n+)<<);
rep(i,,n) l[i]=min(l[i-],s[i].y),r[i]=max(r[i-],s[i].y);
down(i,n,) l1[i]=min(l1[i+],s[i].y),r1[i]=max(r1[i+],s[i].y);
rep(i,,n) {
now=(ll)(s[i-].x-s[].x) * (ll)(r[i-]-l[i-]) + (ll)(s[n].x-s[i].x) * (ll)(r1[i]-l1[i]);
ans=min(ans,now);
}
}
int main ()
{
int miny,minx,maxx,maxy;
miny=minx=,maxy=maxx=;
scanf("%d",&n); rep(i,,n)
{
scanf("%d%d",&s[i].x,&s[i].y),miny=min(miny,s[i].y),maxy=max(maxy,s[i].y);;
maxx=max(maxx,s[i].x); minx=min(minx,s[i].x);
}
ans=(ll)(maxy-miny)*(ll)(maxx-minx),zs=ans;
getans();
rep(i,,n) swap(s[i].x,s[i].y);
getans();
printf("%lld\n",zs-ans);
}

2.Closing the Farm

http://usaco.org/index.php?page=viewproblem2&cpid=646

离线+并查集

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#define N 200020
#include<vector>
using namespace std;
int n,m,a[N],f[N];
bool vis[N],ok[N];
vector<int>G[N];
int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
int main()
{
scanf("%d%d",&n,&m);
for(int i=,a,b;i<=m;i++)
{
scanf("%d%d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
for(int i=;i<=n;i++)
scanf("%d",&a[i]),f[i]=i;
int cnt=;
for(int i=n;i;i--)
{
int u=a[i];
cnt++;vis[u]=;
for(int j=;j<G[u].size();j++)
{
int v=G[u][j];
if(!vis[v])continue;
int fa=find(u),fb=find(v);
if(fa!=fb)
{
if(fa>fb)swap(fa,fb);
f[fb]=fa;
cnt--;
}
}
if(cnt==)ok[i]=;
}
for(int i=;i<=n;i++)
if(ok[i])printf("YES\n");
else printf("NO\n");
}

3.248

http://usaco.org/index.php?page=viewproblem2&cpid=647#

给定一个长度为n的序列,初始元素值为1到40之间的整数,每次操作可以将两个相邻的并且大小相同
的正整数替换成一个比原数大1的正整数。要求最大化最终数列中的最大值。
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=3e5+;
int n,ans,a,f[][maxn];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a);
f[a][i]=i+;
}
for(int i=;i<=;i++)
for(int j=;j<=n;j++)
{
if(!f[i][j])f[i][j]=f[i-][f[i-][j]];
if(f[i][j])ans=max(i,ans);
}
printf("%d",ans);
return ;
}

USACO 2016 US Open Contest, Gold解题报告的更多相关文章

  1. USACO 2016 February Contest, Gold解题报告

    1.Circular Barn   http://www.usaco.org/index.php?page=viewproblem2&cpid=621 贪心 #include <cstd ...

  2. USACO 2016 January Contest, Gold解题报告

    1.Angry Cows http://www.usaco.org/index.php?page=viewproblem2&cpid=597 dp题+vector数组运用 将从左向右与从右向左 ...

  3. 【二分+拓扑排序】Milking Order @USACO 2018 US Open Contest, Gold/upc_exam_6348

    目录 Milking Order @USACO 2018 US Open Contest, Gold/upc_exam_6348 PROBLEM 题目描述 输入 输出 样例输入 样例输出 提示 MEA ...

  4. USACO Section1.4 Mother's Milk 解题报告

    milk3解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  5. USACO Section1.2 Name That Number 解题报告

    namenum解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...

  6. USACO Section1.1 Friday the Thirteenth 解题报告

    friday解题报告 —— icedream61 博客园(转载请注明出处) -------------------------------------------------------------- ...

  7. USACO Section1.3 Ski Course Design 解题报告

    skidesign解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...

  8. USACO Section 1.3 Prime Cryptarithm 解题报告

    题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...

  9. 【LeetCode】544. Output Contest Matches 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...

随机推荐

  1. 全局变量的使用【C++/Qt】

    转:https://blog.csdn.net/caoshangpa/article/details/51104022 一.使用extern关键字 cglobal.h #ifndef CGLOBAL_ ...

  2. Jwt访问api提示401错误 Authorization has been denied for this request

    教程  http://bitoftech.net/2015/02/16/implement-oauth-json-web-tokens-authentication-in-asp-net-web-ap ...

  3. Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister

    http://codeforces.com/contest/812/problem/B 题意: 有n层楼,每层楼有m个房间,1表示灯开着,0表示灯关了.最两侧的是楼梯. 现在每从一个房间移动到另一个房 ...

  4. python 获取进程执行的结果

    import subprocessp = subprocess.Popen([r'ls'],stdout=subprocess.PIPE) result = p.stdout.read()print( ...

  5. php 获取某个日期n天之后的日期

    <?php $date=date_create("2013-03-15"); date_add($date,date_interval_create_from_date_st ...

  6. Java字符串分割(转)

    java.lang.String 的 split() 方法, JDK 1.4 or later public String[] split(String regex,int limit) 示例代码 p ...

  7. 单例模式(Singleton-Pattern)百媚生

    1 动机 对于系统中的某些类来说,只有一个实例很重要,例如,一个系统中可以存在多个打印任务,但是只能有一个正在工作的任务;一个系统只能有一个窗口管理器或文件系统;一个系统只能有一个计时工具或ID(序号 ...

  8. 并发编程-synchronized关键字大总结

    0.synchronized 的特点: 可以保证代码的原子性和可见性. 1.synchronized 的性质: 可重入(可以避免死锁.单个线程可以重复拿到某个锁,锁的粒度是线程而不是调用).不可中断( ...

  9. Java回顾之网络通信

    在这篇文章里,我们主要讨论如何使用Java实现网络通信,包括TCP通信.UDP通信.多播以及NIO. TCP连接 TCP的基础是Socket,在TCP连接中,我们会使用ServerSocket和Soc ...

  10. 牛客网——G大水题

    链接:https://www.nowcoder.net/acm/contest/75/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...