洛谷 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. Luogu P5363 [SDOI2019]移动金币

    话说这题放在智推里好久了的说,再不写掉对不起自己233 首先你要知道一个叫做阶梯Nim的东西,具体的可以看这篇博客 那么我们发现这和这道题的关系就很明显了,我们把两个金币之间的距离看作阶梯Nim的每一 ...

  2. SQL 错误: ORA-65096: 公用用户名或角色名无效 65096. 00000 - "invalid common user or role name" *Cause: An attempt was made to create a common user or role with a name

    在Oracle SQL Developer中,试图创建RD用户时,出现了如下的错误: 在行: 上开始执行命令时出错 - 错误报告 - SQL 错误: ORA: 公用用户名或角色名无效 . - &quo ...

  3. Java 未来行情到底如何,来看看各界人士是怎么说的

    这是黄小斜的第102篇文章 作者 l 黄小斜 来源 l 公众号[程序员黄小斜](ID:AntCoder) 转载请联系作者(wx_ID:john_josh) Java从出生到现在已经走过了 20 多个年 ...

  4. Pencil 基于Electron的GUI原型工具之菜单三探 印象笔记同步

    今天一鼓作气实现Pencil整合印象笔记同步的功能. 缘起,像Sketch或者Adobe XD等一些工具都开始陆续支持整合阿里巴巴的"语雀"云服务,将设计文档同步到云端,便于团队协 ...

  5. 《一起学mysql》3

    索引和查询优化   为什么要索引? 想想我们上小学的时候是怎么查字典的,比方查 理想的 “理”,首先在索引里找到声母 “l”,再找到 “li” 找到 “li”所在的页数,   我们之前建的所有mysq ...

  6. 03Shell条件测试

    条件测试 Shell 条件测试 格式 1: test 条件表达式 格式 2: [ 条件表达式 ] 格式 3: [[ 条件表达式 ]] 具体参数说明可以通过 man test 进行查看 文件测试 [ 操 ...

  7. python 中in 的 用法

    1.   作用为 成员运算符   在字符串内操作,如果字符串包含相关字符 则返回True,如果不包含则返回False   当然处理不单单是只有单个字符,多个连续的字符也是可以处理的 # 单个字符 a= ...

  8. python asyncio wait和gather

    1. wait, 等待某某执行完成以后才执行下一步 FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED FIRST_EXCEPTION = con ...

  9. asp.net core系列 63 领域模型架构 eShopOnWeb项目分析 上

    一.概述 本篇继续探讨web应用架构,讲基于DDD风格下最初的领域模型架构,不同于DDD风格下CQRS架构,二者架构主要区别是领域层的变化. 架构的演变是从领域模型到CQRS,  一开始DDD是用领域 ...

  10. vuex无法获取getters属性this.$store.getters.getCurChildId undefined

    问题描述 this.$store.getters.getCurChildId undefined 这是因为我们设置了命名空间namespaced: true, 在vuex官网中对命名空间的描述如下: ...