B. Find The Bone

本文解析了一个关于魔术表演中骨骸移动位置的算法问题,通过一系列杯子交换操作后确定骨骸最终位置。讨论了输入输出格式、边界条件处理及性能优化等关键问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. Find The Bone
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Zane the wizard is going to perform a magic show shuffling the cups.

There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i.

The problematic bone is initially at the position x = 1. Zane will confuse the audience by swapping the cups k times, the i-th time of which involves the cups at the positions x = ui and x = vi. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations.

Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at x = 4 and the one at x = 6, they will not be at the position x = 5 at any moment during the operation.

Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone.

Input

The first line contains three integers nm, and k (2 ≤ n ≤ 1061 ≤ m ≤ n1 ≤ k ≤ 3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.

The second line contains m distinct integers h1, h2, ..., hm (1 ≤ hi ≤ n) — the positions along the x-axis where there is a hole on the table.

Each of the next k lines contains two integers ui and vi (1 ≤ ui, vi ≤ nui ≠ vi) — the positions of the cups to be swapped.

Output

Print one integer — the final position along the x-axis of the bone.

Examples
input
7 3 4
3 4 6
1 2
2 5
5 7
7 1
output
1
input
5 1 2
2
1 2
2 4
output
2
Note

In the first sample, after the operations, the bone becomes at x = 2x = 5x = 7, and x = 1, respectively.

In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground.

题解:挺水的,但是一直WA,简直要哭,第一个坑是第一个cup就有可能有洞,第二个坑是,判断条件稍微长点或者多个分支就会Time Limit,真是惨痛的教训。

代码如下:

//
//  main.cpp
//  B. Find The Bone
//
//  Created by 徐智豪 on 2017/4/18.
//  Copyright © 2017年 徐智豪. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;
int n,m,k;
bool h[1000015]={false};
int bones=1;
int main(int argc, const char * argv[]) {
    cin>>n>>m>>k;
    int holes;
    for(int i=1;i<=m;i++)
    {
        cin>>holes;
        h[holes]=1;
    }
    int u,v;
    bool flag=0;
    for(int i=0;i<k;i++)
    {
        scanf("%d%d",&u,&v);
       if(h[1]==true)
       {
           bones=1;
           flag=true;
       }
        if((bones==u||bones==v)&&!flag)
            bones=u+v-bones;
        if(h[bones]==true)
            flag=true;
    }
    cout<<bones<<endl;
    return 0;
}


我正在开发一个blender插件,现在我有两个资产,一个是choosename,它对应的是我的角色骨架的名字,一个是refdummy,它对应的是场景中的拥有动画的一套虚拟物体,它由多个虚拟物体组成,且虚拟物体直接按一定层级关系进行排列。角色骨架中拥有一套正确的可以正常使用的骨骼,该套骨骼的根对象命名为“Master”,“Master”对象的直接子层级存在名为“Root”的骨骼对象,在Root对象的后续子层级中存在其他骨骼;refdummy对象的根对象命名同样包含Master,且refdummy对象的直接子层级同样存在“Root”对象,在Root对象的后续子层级中存在其他拥有动画信息的虚拟物体,骨架对象和虚拟对象两者的子层级中的Root对象有着相同的层级关系,且Root对象的后续层级命名也两两相同。现在我需要你实现功能,选中骨架对象,进入“姿态模式”,随后将refdummy对象根对象及其后续所有对象中当前帧的transform命名对应、层级对应的复制给姿态模式下骨架模型的骨骼上。简单来说,我需要将一个dummy动画信息转移到另一个骨骼动画信息上。 补充说明,进行复制变换前,参考对象的根对象Master在物体模式下的scale为-0.01,其他为子对象1,骨架对象的根对象的Master在姿态模式下的scale是1,其他子对象也是1;进行复制变换后的正确结果为,参考对象的根对象Master在物体模式下的scale为-0.01,其他为1,骨架对象的根对象在姿态模式下的scale是-1,其他子对象都为1。 请参考我的描述,为我完整实现一个blender插件代码,以此为基础class CopyBonePoseOperator(bpy.types.Operator): bl_idname = "character.copy_bone_pose" bl_label = "Copy Bone Pose" def execute(self, context):
最新发布
07-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值