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的邮票,可以推出 ...
随机推荐
- 关于webpack的面试题
随着现代前端开发的复杂度和规模越来越庞大,已经不能抛开工程化来独立开发了,如react的jsx代码必须编译后才能在浏览器中使用:又如sass和less的代码浏览器也是不支持的. 而如果摒弃了这些开发框 ...
- vue项目搭建介绍01
目录 vue项目搭建介绍01 vue 项目框架环境搭建: 创建项目: vue 项目创建流程: vue项目搭建介绍01 vue 项目框架环境搭建: vue 项目框架: vue django(类似)(vu ...
- vscode配置python环境-运行调试-windows环境
官方文件介绍 https://code.visualstudio.com/docs/languages/python 准备: vscode下载安装 python3版本下载(安装时可以选择添加环境变量, ...
- 一、SqlServer查询今天的数据-多写法对比性能问题
-- 目标:查询当天的所有数据 -- 说明:表数据行数:960w --方法一:使用格式化被查询条件与格式化当前时间比对 ),)),) --方法二:使用函数DATEDIFF 比对 --方法三:使用传统比 ...
- Springboot使用ehcache缓存
本文部分步骤继承于springboot使用cache缓存,如果有不清楚的,请移驾springboot使用cache缓存 ehcache是一种广泛使用的开源Java分布式缓存.主要面向通用缓存,Java ...
- Pencil 基于Electron的GUI原型工具之菜单三探 印象笔记同步
今天一鼓作气实现Pencil整合印象笔记同步的功能. 缘起,像Sketch或者Adobe XD等一些工具都开始陆续支持整合阿里巴巴的"语雀"云服务,将设计文档同步到云端,便于团队协 ...
- 绿联Type-C千兆网卡AX88179芯片驱动(苹果Mac OSX系统)CM141丨CM179
绿联Type-C千兆网卡AX88179芯片驱动(苹果Mac OSX系统)CM141丨CM179 下载地址:https://www.lulian.cn/download/6-cn.html AX8817 ...
- CSS改变浏览器默认滚动条样式
前言 最近总是看到某网站滚动条不是浏览器默认样式,而是自定义样式 比如我博客的滚动条,自定义滚动条样式和hover前后的效果 顿时来了兴致和有一个疑问,这是怎么实现的呢? 解决 注:经测试,目 ...
- Zookeeper 到底能帮我们解决哪些问题?
Zookeeper 从设计模式角度来看,是一个基于观察者模式设计的分布式服务管理框架,它负责存储和管理大家都关心的数据,然后接受观察者的注册,一旦这些数据的状态发生变化,Zookeeper 就将负责通 ...
- 使用wireshark学习TCP
TCP标志位: 在TCP传输中,标志位用于表示特定的连接状态或提供额外信息.每个标志位占用1比特.常用的TCP标志位包含以下几种: SYN Synchronous,TCP三次握手建立连接的第一步,主动 ...