洛谷 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

4
0 0
1 0
1 1
0 1

Sample Output

2

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的更多相关文章

  1. Usaco Training [1.3] wormhole

    传送门 解题要素:代码能力 解题步骤:理解题意 - >搜索枚举所有可能的配对情况 - >判断冲突并求解 - >调试 一. 理解题意 这里讲几个不容易理解的点: 1. +x方向 即向右 ...

  2. [题解]USACO 1.3 Wormholes

    Wormholes Farmer John's hobby of conducting high-energy physics experiments on weekends has backfire ...

  3. USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)

    这题可真是又让我找到了八数码的感觉...哈哈. 首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了. 这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我 ...

  4. 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&& ...

  5. USACO 1.3 Wormholes - 搜索

    Wormholes Farmer John's hobby of conducting high-energy physics experiments on weekends has backfire ...

  6. Luogu USACO Training 刷水记录

    开个坑记录一下刷USACO的Training的记录 可能会随时弃坑 只有代码和做法简述 可能没有做法简述 [USACO1.1]你的飞碟在这儿Your Ride Is He… 模拟,细节已忘 #incl ...

  7. USACO Section1.3 Wormholes 解题报告

    wormhole解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------- ...

  8. 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 ...

  9. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

随机推荐

  1. Python实现网络多人聊天室 - Windows

    项目名称:多人聊天室项目结构: client.py server.py settings.py项目思路:服务端接收客户端连接,客户端发送信息给服务端,服务端将信息发送给所有客户端.项目实现:主进程负责 ...

  2. ASP.NET开发实战——(八)ASP.NET MVC 与数据库之MySQL

    之前介绍了My Blog如何使用ADO.NET来访问SQL Server获取数据.本章将介绍如何使用My SQL来完成数据管理. 在使用My SQL之前需确保开发环境中安装了My SQL数据库和Con ...

  3. [日常] SNOI2019场外VP记

    SNOI2019场外VP记 教练突然说要考一场别省省选来测试水平...正好还没看题那就当VP咯w... Day 1 八点开题打 .vimrc. 先看了看题目名...一股莫名鬼畜感袭来... 怎么T1就 ...

  4. [转]numpy的getA()/getA1()/getH()/getI()函数

    转自https://blog.csdn.net/weixin_42906066/article/details/82625779 1.mat.getA() 将自身矩阵变量转化为ndarray类型的变量 ...

  5. jquery 属性名修改

    jquery   attr <script> // 获取class 名 $(".box").attr("class") // 修改或添加class名 ...

  6. MySQL数据库中查询表的所有列名

    MySQL数据库中: 查询某个数据库中某个表的所有列名 SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ...

  7. Linux磁盘系统——磁盘系统简介

    Linux磁盘系统——磁盘系统简介 摘要:本文主要学习了Linux系统中有关磁盘的一些知识. 文件系统 说明 硬盘是用来存储数据的,可以将其想象成柜子,只不过柜子是用来存储衣物的.新买来的硬盘,通常要 ...

  8. Linux入门——初识Linux

    Linux入门——初识Linux 摘要:本文主要说明了Linux是什么,Linux发展历史,以及同Linux系统有关的一些基本知识. 简介 操作系统 Linux系统同Windows系统.Mac系统一样 ...

  9. jsonHelper帮助类

    使用前,需引用开源项目类using Newtonsoft.Json 链接:https://pan.baidu.com/s/1htK784XyRCl2XaGGM7RtEg 提取码:gs2n using ...

  10. 浅析Java中线程组(ThreadGroup类)

    Java中使用ThreadGroup类来代表线程组,表示一组线程的集合,可以对一批线程和线程组进行管理.可以把线程归属到某一个线程组中,线程组中可以有线程对象,也可以有线程组,组中还可以有线程,这样的 ...