UVa 10935 - Throwing cards away I

MicroPython跨平台移植实战:从源码解析到STM32+FreeRTOS部署 本文详细解析了MicroPython的跨平台移植实战,重点介绍了如何将其从源码开始,成功部署到STM32微控制器并运行于FreeRTOS实时操作系统。内容涵盖源码结构解析、编译环境搭建、内存管理协调、FreeRTOS任务集成、数学库(math)启用与优化,以及自定义模块开发等核心步骤,为开发者提供了一套完整的、可操作的嵌入式Python移植方案。 阅读详情

I Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck: Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck. Your task is to find the sequence of discarded cards and the last, remaining card.

Input

Each line of input (except the last) contains a number n ≤ 50. The last line contains ‘0’ and this line should not be processed.

Output

For each number from the input produce two lines of output. The first line presents the sequence of discarded cards, the second line reports the last remaining card. No line will have leading or trailing spaces. See the sample for the expected format.

Sample Input

7

19

10

6

0

Sample Output

Discarded cards: 1, 3, 5, 7, 4, 2

Remaining card: 6 Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 4, 8, 12, 16, 2, 10, 18, 14

Remaining card: 6 Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8

Remaining card: 4 Discarded cards: 1, 3, 5, 2, 6

Remaining card: 4


题解:很显然这是约瑟夫环问题,用队列来做就简单多了,每次抽两张卡片,第一张踢出队列另一张加入队列尾部,一直循环直至只有一个元素为止。

#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n,a,b;
    while(cin>>n&&n)
    {
        queue<int>q;
        for (int i=1; i<=n; i++)  //将所有数字入队
            q.push(i);
        if(n==1) //控制格式
        printf("Discarded cards:\n");
        else
        printf("Discarded cards: ");
        while(!q.empty())
        {
            a=q.front();
            if(q.size()==1) //只有一个元素就跳出
                break;
            if(q.size()!=2)//控制格式
                printf("%d, ",a);
            else
                printf("%d\n",a);
            q.pop();
            b=q.front();
            q.pop();
            q.push(b); //将第二数加入队尾
        }
        printf("Remaining card: %d\n",a);
    }
    return 0;
}



题目链接:https://vjudge.net/contest/169852#problem/C

基于STM32的智能盆栽管家系统设计与实现(开题报告2) 本文设计了一种基于STM32的智能盆栽管家系统,旨在解决传统盆栽养护依赖人工、效率低下的问题。系统以STM32为核心,集成土壤湿度、温湿度及光照传感器,通过WiFi模块实现数据上传与远程控制,配备OLED显示屏本地显示,并利用继电器控制水泵与补光灯实现自动化养护。软件方面开发嵌入式程序、安卓APP及云平台,支持数据采集、远程监控和智能决策。相比现有产品,本系统具有成本低、扩展性强等优势,可满足家庭用户对植物精细化管理的需求。研究计划12周完成,包括硬件设计、软件开发、系统测试等环节,最终形成一套完整的智能盆 阅读详情

相关推荐

创新实训项目博客:基于LoRA的医疗大模型高效微调实战

预训练大语言模型(LLMs)虽然具备了广泛的知识和一定的通用能力,但在特定领域(如医疗)或特定任务(如遵循特定指令格式进行思考链推理)上,其表现往往不尽如人意。微调(Fine-tuning)能够使模型学习到特定领域的数据分布和任务模式,从而在目标任务上获得更好的性能,使其更贴合实际应用需求。使用Unsloth框架加载并以4-bit量化模型。基于数据集,构建了包含明确思考链引导的训练Prompt。配置了LoRA参数,并使用SFTTrainer在单张T4 GPU上对模型进行了高效微调。

m0_73556916的博客 1290

UVA - 10935 Throwing cards away I 【queue】

Description Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the d...

一定要站在自己热爱的生活里闪闪发光 3万+

SRAM ECC原理与应用:从汉明码到高可靠嵌入式系统设计

在嵌入式系统与高可靠性计算领域,内存数据完整性是系统稳定运行的基石。软错误(Soft Error)由宇宙射线或芯片内部粒子引发,可能导致存储单元发生位翻转,进而引发程序跑飞或数据损坏。为应对这一物理层挑战,错误校验与纠正(ECC)技术应运而生,其核心原理基于扩展汉明码,通过增加校验位实现单错误纠正、双错误检测(SECDED)能力。这项技术通过硬件透明纠错,在提升系统可靠性的同时,几乎不影响访问性能。在汽车电子、工业控制及航空航天等对安全性要求极高的场景中,ECC已成为保障长期稳定运行的关键硬件机制。本文聚焦

weixin_28728265的博客 531

UVA 10935 - Throwing cards away I

Problem B: Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at

1482

在Ubuntu 22.04上从零搭建FVCOM环境:手把手搞定Linux、Intel编译器与NetCDF库

本文详细指导在Ubuntu 22.04上从零搭建FVCOM环境,涵盖Linux系统配置、Intel编译器安装、NetCDF库编译及常见问题解决。通过手把手教程,帮助科研人员高效完成水动力数值模拟环境的部署,特别适合水环境研究领域的初学者。

weixin_30613727的博客 650

CVPR2023新作HAT实战:5分钟搞定图像超分辨率重建(附代码)

本文介绍了CVPR2023新作HAT模型在图像超分辨率重建中的实战应用。HAT通过创新的混合注意力机制,显著提升了图像重建质量,能激活更多有效像素并减少伪影。文章提供了从环境配置到模型部署的完整指南,帮助开发者在5分钟内快速实现图像超分辨率重建,并附有代码示例和性能优化技巧。

weixin_29062613的博客 238

UVa 10935 Throwing cards away I

题目大意: 题目链接 注释代码: 无注释代码: 单词解释: trailing:

源代码 621

Nginx的启动、停止与重启命令(非yum方式安装)图解版

目录一、Nginx启动二、Nginx停止的三种方式2.1、第一种方式(从容停止)2.2、第二种方式(快速停止)2.3、第三种方式(强制停止)三、Nginx重启3.1、首先,验证nginx配置文件是否正确3.1.1、验证nginx配置文件(方法一)3.1.1、验证nginx配置文件(方法二)3.2、最后,重启Nginx服务3.2.1、重启Nginx服务(方法一)3.2.2、重启Nginx服务(方法二) 一、Nginx启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 /usr/loc

小志的博客 6852

Throwing cards away I UVA - 10935

题目链接:https://cn.vjudge.net/problem/UVA-10935 为什么出这么奇怪的测试点。。。。 代码: #include &amp;lt;bits/stdc++.h&amp;gt; using namespace std; int main() { freopen(&quot;i.txt&quot;, &quot;r&quot;, stdin); int n; while(cin &a

qq_43185391的博客 150

Hermes-Agent-完整指南

Hermes Agent 是由 **Nous Research** 开发的一款**自我改进型 AI Agent**,具有内置的学习闭环系统。它的核心理念是"一个与你共同成长的 Agent"。- 能够从经验中创建技能(Skill-Learning Automated),在使用过程中自我改进, 跨会话持久记忆, 深度用户建模

liu_zhiyi的博客 3037

大模型选型实战:为OpenClaw匹配最优“大脑”的全维度考量

大模型不是越贵越好,也不是参数越高越好,适合自己的使用场景才是最好的。按照我的方法,先明确自己的需求,再选对应的模型,配置多模型自动路由,既能保证体验,又能最大限度降低成本。我自己用这套配置用了半年多,不管是写文章、写代码还是处理复杂问题,都完全够用,成本也很低,大家可以参考一下。如果不知道选什么模型,可以在评论区说一下你的使用场景。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 343

UVa 10935 Throwing cards away I 卡片游戏 题解

英文 Description Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in ...

ZJ_MRZ的博客 542

K-Core, K-Shell & K-Crust傻傻分不清楚

K-Core(K-核)就是所有大于等于K的K-Shell的并集;K-Crust(K-皮)就是所有小于等于K的K-shell的并集。

欢迎订阅 -- 小源笔迹 2256

Uva 10935 Throwing cards away I

Throwing cards away I Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description Given is an ordered deck of n cards numbered 1to n with

菜鸟起飞的平台 375

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Throwing cards away I(UVA 10935)

似乎也没必要专门写一个函数。倒是输出格式一直没搞好。

Fool256353的博客 415

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

UVA10935 Throwing cards away I 卡片游戏 解题报告

桌上有n(n≤50)张牌,从第一张牌(即位于顶面的牌)开始,从上往下依次编号为1~n。当至少还剩下两张牌时进行以下操作:把第一张牌扔掉,然后把新的第一张牌放到整叠牌的最后。输入每行包含一个n,输出每次扔掉的牌以及最后剩下的牌。题目怎么说你就怎么做,非常直球,很显然是维护一个队列。

qq_45554473的博客 493

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

UVA10935 Throwing cards away I【模拟+queue+循环队列】

Given is an ordered deck of n cards numbered 1to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck:        Thr...

海岛Blog 2532

UVA 10935 Throwing cards away I

题目链接:https://vjudge.net/problem/UVA-10935 题意:桌子上有n(n Sample Input 7 19 10 6 0 Sample Output Discarded cards: 1, 3, 5, 7, 4, 2 Remaining card: 6 Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 1

CS33sun的博客 372

Uva10935 - Throwing cards away I

一.题目 题目链接:Uva10935 二.思路 典型的队列,对于每次的排,把第一个pop出来输出,第二个pop出来重新push进队尾,只剩1张牌的时候结束,注意只有一张牌时候的情况,详情看代码注释。 三.源代码 #include #include using namespace std; int main() { queue cards; //用队列做容器 int n, t

CSerwangjun的博客 379

Uva - 10935 - Throwing cards away I

Problem B: Throwing cards away I Given is an ordered deck ofncards numbered 1 tonwith card 1 at the top and cardnat the bottom. The following operation is performed as long as th...

anpi3191的博客 143

UVA-10935 Throwing cards away I

Vjudge题目链接,STL的队列,模拟队列即可,注意输入n=1的情况(坑点,每行首尾没空格)。 #include<cstdio> #include<iostream> #include<queue> using namespace std; int main(){ int n; while(~scanf("%d", &n) &&...

good vegetable! 228
上一篇: 《神女峰》 舒婷
下一篇: Foreign Exchange
也道长
博客等级 码龄9年 11粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值