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 ...
随机推荐
- CSS3动画库——animate.css
初见animate.css的时候,感觉很棒,基本上很多常用的CSS3动画效果都帮我们写好了,所以想要哪一种效果直接就可以拿过来用,甚是方便: 效果展示官网:http://daneden.github. ...
- Dekker算法在多核处理器下的失效
Dekker algorithm是一种著名的并发编程的算法,Dekker算法的核心部分是一组对称的代码来访问一组共享变量,使得两个线程不可能同时进入临界区(只要cpu内存模型是遵循顺序一致性的),从而 ...
- Michael-Scott非阻塞队列(lock-free)算法的C实现
Michael-Scott非阻塞队列算法,即MS-queue算法,是1 9 9 6 年由Maged . M .Michael and M. L. Scott提出的,是最为经典的并发FIFO队列上的算法 ...
- HDU 4990 Reading comprehension(矩阵快速幂)题解
思路: 如图找到推导公式,然后一通乱搞就好了 要开long long,否则红橙作伴 代码: #include<set> #include<cstring> #include&l ...
- SDN前瞻 网络的前世今生
本文基于SDN导论的视频而成:SDN导论 目前网络层面流行的技术概念:虚拟中心:公有云私有云:数据中心等等. SDN主要的模拟器:Mininet OpenDaylight(Cisco) ONOS(AT ...
- Question: Database Of Tumor Suppressors And/Or Oncogenes
https://www.biostars.org/p/15890/ 71 5.9 years ago by Malachi Griffith ♦16k Washington Univers ...
- CSS 再学习,文本处理
文本缩进(对p,div有效:对span无效) p {text-indent: 5em;} Tips:一般来说,可以为所有块级元素应用 text-indent,但无法将该属性应用于行内元素(span), ...
- 使用由 Intel MKL 支持的 R
我们通常使用的 R 版本是单线程的,即只使用一个 CPU 线程运行所有 R 代码.这样的好处是运行模型比较简单且安全,但是它并没有利用多核计算.Microsoft R Open(MRO,https:/ ...
- [学习笔记]ST表
ST表 给定一个数列$a,O(nlogn)$预处理,$O(1)$查询数列在区间$[l,r]$的最值. 本文介绍求最大值. 实现 预处理 $st[i][j]$表示$max\{a_k\}(k\in[i,i ...
- hihocoder1513
https://hihocoder.com/problemset/problem/1513 五维偏序问题,直接bitset压位,复杂度O(n^2/32) (本来想写三维偏序,但是cdq不会只好写写五维 ...