POJ1978浅析------Hanafuda Shuffle

基于FreeRedis实现的.NET Redis客户端缓存缓存键条件优雅过滤 在.NET开发中,使用Redis作为缓存解决方案是很常见的。FreeRedis是一个功能强大的Redis客户端库,它提供了丰富的功能和灵活性,使我们能够轻松地与Redis进行交互。在本文中,我们将探讨如何使用FreeRedis实现缓存键条件的优雅过滤,以提高缓存的效率和准确性。 阅读详情
Hanafuda Shuffle
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 3548 Accepted: 2024

Description

There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for Japanese card game 'Hanafuda' is one such example. The following is how to perform Hanafuda shuffling.

There is a deck of n cards. Starting from the p-th card from the top of the deck, c cards are pulled out and put on the top of the deck, as shown in Figure 1. This operation, called a cutting operation, is repeated.

Write a program that simulates Hanafuda shuffling and answers which card will be finally placed on the top of the deck.

Figure 1: Cutting operation

Input

The input consists of multiple data sets. Each data set starts with a line containing two positive integers n (1 <= n <= 50) and r (1 <= r <= 50); n and r are the number of cards in the deck and the number of cutting operations, respectively.

There are r more lines in the data set, each of which represents a cutting operation. These cutting operations are performed in the listed order. Each line contains two positive integers p and c (p + c <= n + 1). Starting from the p-th card from the top of the deck, c cards should be pulled out and put on the top.

The end of the input is indicated by a line which contains two zeros.

Each input line contains exactly two integers separated by a space character. There are no other characters in the line.

Output

For each data set in the input, your program should write the number of the top card after the shuffle. Assume that at the beginning the cards are numbered from 1 to n, from the bottom to the top. Each number should be written in a separate line without any superfluous characters such as leading or following spaces.

Sample Input

5 2
3 1
3 1
10 3
1 10
10 1
8 3
0 0

Sample Output

4
4

Source

Japan 2004 Domestic

 

题目类型:简单数学计算

 

题目大意:

        一副纸牌,共计n张。第1~n张牌的值从上到下依次是:n,n-1,……,3,2,1。对这些牌进行cut操作:从第p张牌依次取出c张放在牌首。进行 r 次cut操作。

题目浅析:

        数据量比较小,将纸牌模拟为数组,直接移动就行。

我的代码:

#include<stdio.h>
int main()
{
    int n,r,i,j;
    int p,c;
    int a[60],temp[60];
    while(scanf("%d%d",&n,&r)&&n&&r)
    {
        for(i=1;i<=n;i++)
            a[i]=n-i+1;
        while(r--)
        {
            scanf("%d%d",&p,&c);
            for(i=p,j=1;j<=c;i++,j++)
                temp[j]=a[i];    
            for(i=p-1;i>=0;i--)
                a[i+c]=a[i];  
            for(i=1;i<=c;i++)
                a[i]=temp[i];
        }
        printf("%d\n",a[1]);                                
    }
    return 0;    
}


 

 

 

 

手把手教你学Simulink——机器人控制场景实例:基于Simulink的双足人形机器人步态生成与ZMP稳定控制仿真 ZMP是地面上合力矩在水平方向为零的点。对于平面行走: [ x_{\text{zmp}} = x_c - \frac{z_c}{g} \ddot{x}_c ]📌稳定性判据ZMP必须始终位于支撑脚的凸包(即脚掌范围内)本文完成了基于Simulink的双足人形机器人ZMP稳定控制仿真,实现了:✅ 基于LIPM生成稳定CoM轨迹✅ 构建ZMP参考与验证机制✅ 设计简化踝关节PD控制器✅ 验证ZMP始终位于支撑脚内 → 动态平衡✅ 为人形机器人步态规划奠定理论基础。 阅读详情

相关推荐

告别混乱代码!在Arduino IDE中管理多文件项目的5个必备技巧

本文分享了在Arduino IDE中管理多文件项目的5个必备技巧,帮助开发者告别混乱代码。通过代码分割和模块化设计,提升编译效率、降低内存占用,并实现功能解耦。重点介绍了头文件设计、CPP文件实现、调试技巧和工业级目录结构,让你的Arduino项目像乐高积木一样清晰易维护。

fun88的博客 361

Shuffle Cards (STL rope平衡树库)

本题链接:登录—专业IT笔试面试备考平台_牛客网 输出 2 3 4 1 5 样例2: 输入 输出 3 4 1 2 5 样例3: 输入 输出 3 4 1 5 2 思路: 这道题,其实就是个模拟题,根据题意。 第一行输入,n 为排列数 1~n,初

Angindem博客 1203

Unity3D安装:离线安装 Unity

Unity 下载助手 (Download Assistant) 支持离线部署。在这种部署方式中,可下载用于安装 Unity 的所有文件,然后生成脚本以便在未接入互联网的其他计算机上重复相同的安装。运行下载助手,并在一台计算机上正常安装 Unity。此计算机必须有足够的可用磁盘空间来下载所有文件。单击下拉选单并选择 __Custom__,然后选择要将文件下载到的位置。打开 PC 的文件管理器,导航到之前指定的自定义位置文件夹,然后在该文件夹内查找。整理翻译,转载请注明出处!

ygtu2018的博客 3255

Shuffle Cards (splay)

题目大意:给定一个数组1 2 3 4 5… 有m次操作,每次给定一个p和s,然后将数组中[p,p+s-1]中的数放到数组最前方。最后输出操作完后的顺序 实际上这个操作转化成可以分成三次翻转 假设p=2,s=3, 1:翻转[1,p+s-1] 4 3 2 1 5 2:翻转[1,3] 2 3 4 1 5 3 翻转[4,4] 2 3 4 1 5 形式化来讲就是 int l = 1, r = p + s - 1; rev(l, r); // rev(l, s); rev(s + 1, r); 显然,这

fdxgcw的博客 258

双相机坐标系标定

工业双相机对位标定

sinat_33762356的博客 8317

东方财富网API接口逆向分析:手把手教你破解那个带jQuery回调的股票数据接口

本文详细解析了东方财富网股票数据API接口的逆向工程实战技巧,重点介绍了JSONP接口的核心机制、参数解析及数据处理方法。通过Python代码示例演示了如何构造请求、处理分页数据及应对反爬策略,帮助开发者高效获取股票数据。文章还提供了完整的爬虫实现案例和常见问题排查指南。

weixin_30790841的博客 716

POJ 1978 Hanafuda Shuffle

Hanafuda Shuffle Description There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for Japanese card game 'Hanafuda' is one such example. The following is how to perform

nudt_oys的博客 493

JDK8升级JDK17过程中遇到的那些坑

JDK8虽然非常好,但是JDK版本已经发布到JDK20了,且JDK8后的版本升级了很多新的特性,如模块化、ZGC以及虚拟线程、结构性并发等,也是非常有吸引力的,所以决定将基于JDK8的项目升级到最近的LTS版本JDK17。

BASK2312的博客 6685

POJ - 1978 Hanafuda Shuffle

最初给牌编号时,编号的顺序是从下到上;洗牌时,认牌的顺序是从上到下。注意使用循环是尽量统一“i”的初始化值,都为“0”或者都为“1”,限界条件统一使用“<”或者“<=”。 POJ - 1978 Hanafuda Shuffle Time Limit: 1000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u D...

weixin_30952535的博客 124

【零基础入门unity游戏开发——2D篇】SpriteEditor图片编辑器

【零基础入门unity游戏开发——2D篇】SpriteEditor图片编辑器

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2330

Node-RED系列(二二):使用dashboard搭配echarts制作漂亮的面板

在node-red中dashboard 是一个很常用的模块,其中它有一个chart节点可以用来制作一些图表,比如柱状图,折线图,饼图,但其中的图表并不是很美观,而且可配置项非常的少。 于是就有很多小伙伴找我做一套比较好看的图表面板,在对比了一下几个图表库,我选中了echarts。 不仅美观大方,而且非常容易集成,配置。下面先来看一下我做的效果。这里是直接做了四个折线图,第一个折线图有动态效果,第二个折线图是一个多线条的折线图,第三个折线图是在一个图例显示两个折线图。第二第三都可以用于数据对比。 第四个折线

知无涯 1万+

rope

链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网   题目描述 Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards game, the very first step in th...

xiaozheng的博客 562

STM32_HAL库—PWM产生指定个数

(一)CubeMX设置: 1. 晶振配置(72M) 2. 引脚配置 3. 中断配置 4. 配置及实现方式 由上推出公式: 机器周期: (72MHz / 36) = 2MHz = 0.5us PWM周期: 0.5 * 100 = 50us = 20kHz 5. 主函数调用PWM函数 HAL_TIM_PWM_Start_IT(&htim3, TIM_CHANNEL_2); //此处一句后可直接进入中断 6. PWM溢出回调函数 void HAL_TIM_PWM_PulseFinished

5526

文章标题 poj 1978 :Hanafuda Shuffle(模拟)

Hanafuda ShuffleDescriptionThere are a number of ways to shuffle a deck of cards. Hanafuda shuffling for Japanese card game ‘Hanafuda’ is one such example. The following is how to perform Hanafuda shuf

Wang_SF2015的博客 572

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

E Card Trick(队列)

Card Trick 时间限制:1000ms | 内存限制:65535KB 难度:3 描述 The magician shuffles a small pack of cards, holds ...

dengjing1200的博客 182

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

zoj 2164 Hanafuda Shuffle

wa了好多次没、一直找不到原因。后来就在网上搜测试数据,得出一个结论,放弃google吧,zf对google太狠了,果断用bing吧http://www.acm-japan.org/past-icpc/domestic2004/index.html测试数据地址。 //2

我辈皆愚 768

POJ 1978 Hanafuda Shuffle G++

n张牌从低到顶编号依次是1到n。洗r次牌,每次洗盘如图,给出pc。求最顶上牌的编号。

woniupengpeng的专栏 247

shuffle a deck of cards

Question: You are given a deck of 52 cards, and you need to shuffle the cards and make sure the order is random. Solution: We can simply use the Durstenfeld and Knuth algorithm to shuffle the cards

Yuwen's Hero 2086

Card Trick

题目描述 The magician shuffles a small pack of cards, holds it face down andperforms the following procedure: 1. The top card is moved to the bottom of the pack. The new top card is dealtface up onto

璐潇晓璐的博客 782

poj 1978 Hanafuda Shuffle

Hanafuda Shuffle Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3395 Accepted: 1939 Description There are a number of ways to shuffle a deck of cards. Hanaf...

weixin_30856725的博客 176

zoj 2164 Hanafuda Shuffle

/* 用栈直接模拟 非常方便! */ #define LOCAL #include&lt;iostream&gt; #include&lt;stack&gt; using namespace std; int main() { #ifdef LOCAL freopen("input.txt","r",stdin); freopen("output.txt","w",s

jinghuainfo 182

A1042. Shuffling Machine(洗牌机)

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak 有54张牌,编号为1~54,初始按编号从小到大排列.........

CYJ2014go的博客 579

[编程题]Shuffling Machine (洗牌程序)

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collaborate with gamblers

Zk 3267

POJ刷题顺序

序号 题目 AC率 通过数 提交数 1000 A+B Problem 0.55 188072 338977 1004 Financial Management 0.41 58282 140301 1003 Hangover 0.48 50457 103742 1002 487-3279 0.17 43922 247299 1005 I Think I Need a Houseboat

Shiina Mashiro no youni 2万+

牛客网暑期ACM多校训练营(第三场)C Shuffle Cards【Splay】

https://www.nowcoder.com/acm/contest/141/C 相邻区间的交换可以通过三次区间反转实现。 而区间反转可以通过Splay高效实现。 #include &lt;cstdio&gt; #include &lt;iostream&gt; #define il inline #define lson l,mid-1,now #define rson mid+1,r...

Irish_Moonshine的博客 562

poj 1721 CARDS 【置换群 】【求最小循环节 再由末序列 求 初序列】

CARDS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1516   Accepted: 810 Description Alice and Bob have a set of N cards labelled with numbers 1 ... N (so th

世界很大 803
上一篇: POJ1922浅析------Ride to School
下一篇: POJ2000浅析------Gold Coins
monkey7777
博客等级 码龄15年 55粉丝 104原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值