bzoj 4995: [Usaco2017 Feb]Why Did the Cow Cross the Road
来源:互联网 发布:配眼镜测得数据的意思 编辑:程序博客网 时间:2024/06/09 16:48
题意
点这里
什么?你说这是英文你不想看?
那我也不告诉你
解法
这题其实我看了官方题解。。
也是英文的。。
就是将奶牛的r为第一关键字,l为第二关键字,从小到大排序
然后将奶牛扫过去
对于每一头奶牛,就找一只剩下的与他l节点最接近的鸡和他尝试配对
配对成功了,就把鸡删掉,然后ans++
这些都可以用set在logn时间做完
不会set的可以看这里点这里
为什么这样是最优的呢?
我们可以分类讨论一下
首先对于两条线段,情况就只有上面两种。。
不想交的就没有画了,显然我选什么和你没有关系
看看图就知道了。。然后我们可以发现,上面的线段只要选择靠近他左端点的,答案都不会差
正确性显然。。
感觉这个贪心题没做出来,真的是最近变水了QAQ
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<set>using namespace std;const int N=20005;int c,n;multiset<int> s;multiset<int>::iterator it;struct qq{ int l,r;}cow[N];bool cmp (qq a,qq b){return a.r==b.r?a.l<b.l:a.r<b.r;}int main(){ scanf("%d%d",&c,&n); for (int u=1;u<=c;u++) { int x; scanf("%d",&x); s.insert(x); } for (int u=1;u<=n;u++) scanf("%d%d",&cow[u].l,&cow[u].r); sort(cow+1,cow+1+n,cmp); int ans=0; for (int u=1;u<=n;u++) { it=s.lower_bound(cow[u].l); if (it!=s.end()&&*it<=cow[u].r) { ans++; s.erase(it); } } printf("%d\n",ans); return 0;}
阅读全文
1 0
- bzoj 4995: [Usaco2017 Feb]Why Did the Cow Cross the Road
- 4992: [Usaco2017 Feb]Why Did the Cow Cross the Road
- bzoj4995: [Usaco2017 Feb]Why Did the Cow Cross the Road
- bzoj4989: [Usaco2017 Feb]Why Did the Cow Cross the Road
- Bzoj4989 [Usaco2017 Feb]Why Did the Cow Cross the Road
- [Usaco2017 Feb]Why Did the Cow Cross the Road
- [Usaco2017 Feb]Why Did the Cow Cross the Road II
- [Usaco2017 Feb]Why Did the Cow Cross the Road III
- bzoj 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- BZOJ 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II LCS
- BZOJ 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II 树状数组优化LCS
- BZOJ 4989: [Usaco2017 Feb]Why Did the Cow Cross the Road 逆序对
- bzoj 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- bzoj 4994: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- bzoj 4996: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- bzoj 4989: [Usaco2017 Feb]Why Did the Cow Cross the Road
- bzoj 4997: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- bzoj 4991: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- ZOJ 2112 Dynamic Rankings
- 负载均衡算法
- 字符串:各种奇葩内置--2017/9/3--2
- 下降子序列的个数等于最长上升子序列的长度
- 修饰符volatile和synchronized的区别联系
- bzoj 4995: [Usaco2017 Feb]Why Did the Cow Cross the Road
- 关于热更新的一些分享
- 51Nod-1137-矩阵乘法
- 662. Maximum Width of Binary Tree
- 在Linux里设置用户环境变量的方法
- Selenium TestNG Java环境搭建过程中所遇问题汇总
- 欢迎使用CSDN-markdown编辑器
- MyCat介绍与配置
- Java中栈的实现原理