LA - 4043 - Ants】的更多相关文章

题意:n只蚂蚁,n棵树,每只蚂蚁要连一棵树,连线(直线)不能相交,给出n只蚂蚁和n棵树的坐标,输出n只蚂蚁所配对的树的编号(1 <= n <= 100, -10000 <= 坐标x, y <= 10000). 题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2044 ——>>二分图…
KM   构图求最小权值匹配 保证最小的权值,所连的边一定是能够不相交的. Ants Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Description Young naturalist Bill studies ants in school. His ants feed on plant-louses that live on…
题意: 有n个蚂蚁n棵树,蚂蚁与树要配对,在配对成功的一对之间连一条线段,要求所有线段不能相交.按顺序输出蚂蚁所匹配的树. 思路: 这个题目真是技巧啊,不能用贪心来为每个蚂蚁选择最近的树,这样很可能是相交了的. 整体最优能让每条线段不相交,证明: 假设a1-b1与a2-b2相交.则dis(a1,b1)+dis(a2,b2)>=dis(a1,b2)+dis(a2,b1).如果我们所决定的最优匹配是按照整体距离最短来匹配的,那么dis(a1,b1)+dis(a2,b2)必定小于dis(a1,b2)+…
题意:每个蚁群有自己的食物源(苹果树),已知蚂蚁靠气味辨别行进方向,所以蚁群之间的行动轨迹不能重叠.现在给出坐标系中n个蚁群和n棵果树的坐标,两两配对,实现以上要求.输出的第 i 行表示第 i 个蚁群应该去哪棵果树.(已知2*n个点互不重合) 容易想到二分完美匹配,但究竟以什么为权值?需要利用一个关系:两条线段如果相交,那么线段长度之和必然大于其四个点不相交的连法对应的线段长度之和.(利用三角不等式可以证明). 如此,求出每个蚁群到每棵果树的曼哈顿距离,只要保证每条匹配边的长度最短,即长度之和最…
题意:给定 n 个只蚂蚁和 n 棵树的坐标,问怎么匹配使得每个蚂蚁到树的连线不相交. 析:可以把蚂蚁和树分别看成是两类,那么就是一个完全匹配就好,但是要他们的连线不相交,那么就得考虑,最佳完美匹配是可以的,为什么呢,假设有两条线段a1-b1和a2-b2,那么如果相交,dist(a1, b1) + dist(a2, b2) > dist(a1, b2) + dist(a2, b1),自己画图看看就好,然后如果是最小的距离,那么就是可以的了,只要在用使得KM匹配时,把权值取反就好. 代码如下: #p…
题目链接:https://vjudge.net/contest/161820#problem/A 题意: n 个 白点,n 个黑点,给出了坐标,求完美匹配后,各点不相交,输出白点对于的黑点编号:(输出输错了 (:´д`)ゞ) 分析:(a1-b1) (a2-b2) 如果这样连接,那么肯定大于 (a1-b2) (a2-b1);也就说,我们要的完美匹配要是权值最小的匹配: 这样,我们的权值,可以全改为负数,这样就可以转为普通的KM算法了: KM算法(我的理解): 可行标  lx(i) + ly(j)>…
题目链接:https://vjudge.net/problem/UVALive-4043 题意: 给出n个白点和n个黑点的坐标, 要求用n条不相交的线段把他们连接起来,其中每条线段恰好连接一个白点和黑点,每个点恰好连接到一条线段.输出每个白点与其相连的黑点的编号. 题解: 1.首先随便配对.然后,如果存在两对黑白点的线段是相交的,那么就交换他们的配对对象.交换之后重新形成的线段就不会相交了(画画图就可看出).而且可以推出一个结论:交换之后,两条线段之和必定变小.这是因为根据三角形定理: 2.有了…
[POJ3565]ANTS 题意:平面上有2*n个点,N白N黑.为每个白点找一个黑点与之连边,最后所有边不交叉.求一种方案. 题解:KM算法真是一个神奇的算法,虽然感觉KM能做的题用费用流都能做~ 本题用到的结论:当选出的点对之间的距离之和最小时,一定使所有边都不交叉 这个感觉很容易理解,自己画画图就能看出来,就是难想啊 然后跑最小权值匹配,方法是将边权都变成相反数,然后跑最大权值匹配 不知道为什么以前写的KM算法会TLE,将求temp的过程拿到主函数里就过了 #include <cstdio>…
layout: post title: 训练指南 UVALive - 4043(二分图匹配 + KM算法) author: "luowentaoaa" catalog: true mathjax: true tags: - 二分图匹配 - 图论 - 训练指南 Ants UVALive - 4043 题意 给你n个白点和n个黑点的平面坐标,要求用n条不相交的线连起来,每条线段连一个白点和黑点,每个点连一条线,也就是匹配.让你输出第i个白点所对应的黑点. 思路 二分图完美匹配问题.但是题目…
Ants Language:Default Ants Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7975 Accepted: 2517 Special Judge Description Young naturalist Bill studies ants in school. His ants feed on plant-louses that live on apple trees. Each ant colony…
两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝向,求所有蚂蚁落下竿子所需要的时间的最大值和最小值. 2.问题1的升级版:把问题1改为已知每只蚂蚁的左端距离和它的朝向,要求按输入顺序输出 t 秒后每只蚂蚁的位置和状态(掉出去,转向中,或者蚂蚁的朝向). 1.POJ 1852 Ants http://poj.org/problem?id=1852…
Description An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When two ants meet they turn back and start walking in opposite d…
一.前言 最近一段时间,网站经常出现两个问题: 1.内存占用率一点点增高,直到将服务器内存占满. 2.访问某个页面时,页面响应过慢,CPU居高不下. 初步判断内存一点点增多可能是因为有未释放的资源一直在占用内存,而cpu居高不下可能是因为执行了耗时的操作. 下面我们就使用ANTS Performance Profiler和ANTS Memory Profiler这两个工具来分析具体原因. ------------------------------------------------------…
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggiornamenti di scarpe da trail che erano svelte e agile in passato ora sembra essere catering per legioni di acquirenti di scarpe arrabbiati che misteri…
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de la saison, bien que ceux-ci comprennent sans aucun doute l'athlète d'entrée destiné à «2016 chaussure de course sur la saison. «Il y a du plaisir à c…
求最短时间和最长时间. 当两个蚂蚁相遇的时候,可以看做两个蚂蚁穿过,对结果没有影响.O(N)的复杂度 c++版: #include <cstdio> #define min(a, b) (a) < (b) ? (a) : (b) #define max(a, b) (a) > (b) ? (a) : (b) int main(void) { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin);…
蚂蚁相撞会各自回头.←可以等效成对穿而过,这样移动距离就很好算了. 末状态蚂蚁的顺序和初状态其实是相同的. 那么剩下的就是记录每只蚂蚁的标号,模拟即可. /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<vector> using namespace std;…
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输入以下内容即可: alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' 保存后,执行 source  .bash_profile…
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi.o .a文件(静态库文件) 创建atoi.a 使用atoi.a .so文件(共享库文件) 创建atoi.so 使用atoi.so .la文件(libtool archive) libtool的使用 1. 创建 Libtool 对象文件 2. 创建 Libtool 库 3. 安装 Libtool 库…
"One thing is for certain: there is no stopping them;the ants will soon be here. And I, for one, welcome ournew insect overlords." Kent Brockman Piotr likes playing with ants. He has n of them on a horizontal pole L cm long. Each ant is facing e…
在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -alF'alias la='ls -A' alias l='ls -CF' 然后 source .bash_profile…
.NET性能调优系列文章 系列文章索引 .NET性能调优之一:ANTS Performance Profiler的使用 .NET性能调优之二:使用Visual Studio进行代码度量 .NET性能调优之三:YSlow相关规则的调优工具和方法 在使用.NET进行快速地上手与开发出应用程序后,接下来面临的问题可能就是程序性能调优方面的问题,而性能调优有时候会涉及方方面面的问题,如程序宿主系统.数据库.网络环境等等,而当程序异常庞大复杂的时候,性能调优将变得更加无从下手. 本系列文章主要会介绍一些.…
7.2 There are three ants on different vertices of a triangle. What is the probability of collision (between any two or all of them) if they start walking on the sides of the triangle? Assume that each ant randomly picks a direction, with either direc…
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <queue> #include <map> #include <set> #include <ctime> #include <cm…
Problem DPiotr's AntsTime Limit: 2 seconds "One thing is for certain: there is no stopping them;the ants will soon be here. And I, for one, welcome ournew insect overlords." Kent Brockman Piotr likes playing with ants. He has n of them on a hori…
string Cookies = string.Empty; /// <summary> /// 获取在线人数 (51.la统计器) /// </summary> /// <param name="siteid">站点ID</param> string TongJi_51La(string siteid) { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem(…
E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex. You are given a tree with n vertices and a root in t…
B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Description It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: eve…
留着当个模板用,在BNU上AC,在LA上RE……可能是java的提交方式不同??? 数和运算符各开一个栈. 表达式从左到右扫一遍,将数存成大数,遇到数压在 数的栈,运算符压在 运算符的栈,每当遇到右括号时,弹出 数的栈 的栈顶头两个元素,弹出 运算符的栈 顶的头一个元素,进行运算,将运算结果压回 数的栈 中.最后输出栈顶元素. 运算过程中把不符合情况的判掉. 我写的第二个java的题,竟然1A……这世界太不可思议了= = import java.util.*; import java.math.…
如果用容斥原理递推的办法,这道题确实和LA 3720 Highway很像. 看到大神们写的博客,什么乱搞啊,随便统计一下,这真的让小白很为难,于是我决定用比较严格的语言来写这篇题解. 整体思路很简单:m*n的方格,其格点是(m+1)*(n+1)的点阵,选三个点有C((m+1)*(n+1), 3)中情况,其中能构成三角形的不容易计算,所以计算它的反面:三个点不能构成三角形,即三点共线的情况. 三点共线的情况也可以再分为三类: ①三点在一条水平线上,共有m*C(n+1, 3)种情况. ②三点在一条竖…