USACO wormhole
洛谷 P1444 [USACO1.3]虫洞wormhole
https://www.luogu.org/problemnew/show/P1444
JDOJ 2386: USACO 2013 Dec Bronze 3.Wormholes
https://neooj.com:8082/oldoj/problem.php?id=2386
Description
Problem 3: Wormholes [Brian Dean, 2013]
Farmer John's hobby of conducting high-energy physics experiments on
weekends has backfired, causing N wormholes (2 <= N <= 12, N even) to
materialize on his farm, each located at a distinct point on the 2D map of
his farm.
According to his calculations, Farmer John knows that his wormholes will
form N/2 connected pairs. For example, if wormholes A and B are connected
as a pair, then any object entering wormhole A will exit wormhole B moving
in the same direction, and any object entering wormhole B will similarly
exit from wormhole A moving in the same direction. This can have rather
unpleasant consequences. For example, suppose there are two paired
wormholes A at (0,0) and B at (1,0), and that Bessie the cow starts from
position (1/2,0) moving in the +x direction. Bessie will enter wormhole B,
exit from A, then enter B again, and so on, getting trapped in an infinite
cycle!
Farmer John knows the exact location of each wormhole on his farm. He
knows that Bessie the cow always walks in the +x direction, although he
does not remember where Bessie is currently located. Please help Farmer
John count the number of distinct pairings of the wormholes such that
Bessie could possibly get trapped in an infinite cycle if she starts from
an unlucky position.
Input
* Line 1: The number of wormholes, N.
* Lines 2..1+N: Each line contains two space-separated integers
describing the (x,y) coordinates of a single wormhole. Each
coordinate is in the range 0..1,000,000,000.
Output
* Line 1: The number of distinct pairings of wormholes such that
Bessie could conceivably get stuck in a cycle walking from
some starting point in the +x direction.
Sample Input
0 0
1 0
1 1
0 1
Sample Output
HINT
INPUT DETAILS:
There are 4 wormholes, forming the corners of a square.
OUTPUT DETAILS:
If we number the wormholes 1..4, then by pairing 1 with 2 and 3 with 4,
Bessie can get stuck if she starts anywhere between (0,0) and (1,0) or
between (0,1) and (1,1). Similarly, with the same starting points, Bessie
can get stuck in a cycle if the pairings are 1-3 and 2-4. Only the
pairings 1-4 and 2-3 allow Bessie to walk in the +x direction from any
point in the 2D plane with no danger of cycling.
#include<cstdio>
#include<algorithm>
using namespace std;
int n,ans;
int v[];
struct node
{
int x,y;
}w[];
bool cmp(node a,node b)
{
if(a.y==b.y)
return a.x<b.x;
return a.y<b.y;
}
int find(int vis,int end,int begin,int way)
{
if(vis!= && end==begin && way==)
return ;
if(way==)
{
if(w[end].y==w[end+].y)
return find(vis+,end+,begin,);
return ;
}
if(way==)
return find(vis+,v[end],begin,);
}
int judge()
{
for(int i=;i<=n;i++)
if(find(,i,i,))
return ;
return ;
}
void dfs(int x)
{
if(x==n+)
{
if(judge())
ans++;
return;
}
if(v[x]==)
{
for(int i=x+;i<=n;i++)
if(v[i]==)
{
v[i]=x;v[x]=i;
dfs(x+);
v[i]=v[x]=;
}
}
if(v[x]!=)
dfs(x+);
return;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",&w[i].x,&w[i].y);
sort(w+,w+n+,cmp);
dfs();
printf("%d",ans);
return ;
}
USACO wormhole的更多相关文章
- Usaco Training [1.3] wormhole
传送门 解题要素:代码能力 解题步骤:理解题意 - >搜索枚举所有可能的配对情况 - >判断冲突并求解 - >调试 一. 理解题意 这里讲几个不容易理解的点: 1. +x方向 即向右 ...
- [题解]USACO 1.3 Wormholes
Wormholes Farmer John's hobby of conducting high-energy physics experiments on weekends has backfire ...
- USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)
这题可真是又让我找到了八数码的感觉...哈哈. 首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了. 这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我 ...
- USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)
usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...
- USACO 1.3 Wormholes - 搜索
Wormholes Farmer John's hobby of conducting high-energy physics experiments on weekends has backfire ...
- Luogu USACO Training 刷水记录
开个坑记录一下刷USACO的Training的记录 可能会随时弃坑 只有代码和做法简述 可能没有做法简述 [USACO1.1]你的飞碟在这儿Your Ride Is He… 模拟,细节已忘 #incl ...
- USACO Section1.3 Wormholes 解题报告
wormhole解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------- ...
- USACO . Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...
- 【USACO 3.1】Stamps (完全背包)
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...
随机推荐
- SDOI2019退役记
\(update:2019-8-15\) 这个坑占了四个月,不填上终归不太好,也不甘心.日子久了,记不太清了,您就当瞧个乐吧. \(Day \ 0\) 下午来到山师大领准考证,晚上一点前就睡了觉. \ ...
- 一种单机支持 JavaWeb 容器万级并发的设想
当前的大部分 Java web 容器基于 Bio 线程模型,例如常见的 tomcat ,默认 200 线程,即 200 连接.由此带来的问题是,如果想提高并发,或者提高资源利用率,就得加大线程数. 如 ...
- 在Ubuntu18.04.2LTS上使用wine安装qq,微信,迅雷,百度网盘,网易云音乐等软件
在Ubuntu18.04.2LTS上使用wine安装qq,微信,迅雷,百度网盘,网易云音乐等软件 一.前言 在Linux上办公有一点一直是大家的痛,那就是这些系统上没有我们常用的一些软件,比如QQ,微 ...
- php explode容易犯的错误
php explode容易犯的错误 <pre> $pos = strpos($v, 'Controller'); if (is_numeric($pos)) { $kongzhiqifeg ...
- IEEE 二进制浮点数的表示
朋友在谈一个物流相关的项目,是以前项目的一个延续,涉及到后台的扩展,手机端的App,外加两个App的对接的蓝牙打印机.这个项目前后说了一个多月了吧,最近才草拟了协议.项目本来不复杂,但是客户却如此的拖 ...
- 明解JAVA 第二章答案
练习2-1 编译错误,无法运行. 练习2-2 package candle1220; class Nightwatch{ public static void main(String[] args) ...
- C++类型处理:typedef decltype
类型别名 类型别名是某种类型的同义词 有两种方法用于定义类型别名,传统方法是使用typedef: typedef double wages; //wages是double的同义词 typedef wa ...
- C# vb .NET生成QR二维码
二维码比条形码具有更多优势,有些场合使用二维码比较多,比如支付.通过将某些数据生成二维码,就可以实现一码走天下.那么如何在C#,.Net平台代码里生成二维码呢?答案是使用SharpBarcode! S ...
- oracle创建删除视图
--删除视图--DROP VIEW CQICC.V_APPLY_RECRUIT; --多表创建视图 CREATE OR REPLACE FORCE VIEW CQICC.V_APPLY_RECRUIT ...
- 教你使用 Swoole-Tracker 秒级定位 PHP 卡死问题
PHPer 肯定收到过这样的投诉:小菊花一直在转!你们网站怎么这么卡!当我们线上业务遇到这种卡住(阻塞)的情况,大部分 PHPer 会两眼一抹黑,随后想起那句名言:性能瓶颈都在数据库然后把锅甩给DBA ...