USACO 2016 US Open Contest, Gold解题报告
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#
#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解题报告的更多相关文章
- USACO 2016 February Contest, Gold解题报告
1.Circular Barn http://www.usaco.org/index.php?page=viewproblem2&cpid=621 贪心 #include <cstd ...
- USACO 2016 January Contest, Gold解题报告
1.Angry Cows http://www.usaco.org/index.php?page=viewproblem2&cpid=597 dp题+vector数组运用 将从左向右与从右向左 ...
- 【二分+拓扑排序】Milking Order @USACO 2018 US Open Contest, Gold/upc_exam_6348
目录 Milking Order @USACO 2018 US Open Contest, Gold/upc_exam_6348 PROBLEM 题目描述 输入 输出 样例输入 样例输出 提示 MEA ...
- USACO Section1.4 Mother's Milk 解题报告
milk3解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- USACO Section1.2 Name That Number 解题报告
namenum解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...
- USACO Section1.1 Friday the Thirteenth 解题报告
friday解题报告 —— icedream61 博客园(转载请注明出处) -------------------------------------------------------------- ...
- USACO Section1.3 Ski Course Design 解题报告
skidesign解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...
- USACO Section 1.3 Prime Cryptarithm 解题报告
题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...
- 【LeetCode】544. Output Contest Matches 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...
随机推荐
- ubuntu18.04下挂载网络文件系统失败【学习笔记】
作者:庄泽彬(欢迎转载,请注明作者) PC: ubuntu18.04 说明: 之前ubuntu16.04下搭建的环境,开发板挂载网络文件系统是ok的,但是换到ubuntu18.04在启动的时候 ...
- notepad++下载32位,安装插件管理
下载32位地址: https://notepad-plus-plus.org/download/v7.6.4.html 下载插件: 链接: https://pan.baidu.com/s/1tRSo4 ...
- Splay树学习
首先给出一论文讲的很好: http://www.docin.com/p-63165342.html http://www.docin.com/p-62465596.html 然后给出模板胡浩大神的模板 ...
- shell 计时获取输入
#!/bin/bash if read -t 5 -p "please enter your name:" name then echo "hello ...
- [java]java String.split()函数的用法分析
转自:http://swiftlet.net/archives/709 一.在java.lang包中有String.split()方法的原型是: public String[] split(Strin ...
- python实现本地批量ping多个IP
本文主要利用python的相关模块进行批量ping ,测试IP连通性. 下面看具体代码(python3): #!/usr/bin/env python#-*-coding:utf-8-*- impor ...
- UVA-10570 Meeting with Aliens (枚举+贪心)
题目大意:将一个1~n的环形排列变成升序的,最少需要几次操作?每次操作可以交换任意两个数字. 题目分析:枚举出1的位置.贪心策略:每次操作都保证至少一个数字交换到正确位置上. # include< ...
- 升级OPENSSH 和 OPENSSL
升级OPENSSH 和 OPENSSL 首先安装telnet服务,防止在操作过程中导致ssh远程中断 # 安装Telnetyum install telnet-server -y chkcon ...
- 【MVC】MusicStore相关资料
引言 当你对MVC的项目结构有一定了解时,那就可以开始学习一个世界级的MVC入门demo--MusicStore.学习的绝招就是把它抄一遍. 相关资料 MVC Music Store Codeple ...
- java之正则表达式的使用1
正则表达式: 主要作用: a.匹配 b.切割 c.替换 d.获取 1.反斜杠和转义字符 废话不多说,直接上demo public static void main(String[] args) { / ...