AT266 迷子のCDケース 题解
2024-09-05 07:18:57
Content
有 \(n+1\) 个碟,编号为 \(0\sim n\),一开始 \(0\) 号碟在播放机上,其他的碟依次放进了 \(n\) 个盒子里面。现在有 \(m\) 次操作,每次操作找到当前在盒子里面的编号为 \(x\) 的碟并和当前正在播放机上的碟交换,求 \(m\) 次操作后 \(n\) 个盒子里面的碟的编号。
数据范围:\(1\leqslant n\leqslant 100,0\leqslant m\leqslant 100,1\leqslant x\leqslant n\)。
Solution
直接暴力扫一遍,找到了就和当前在播放机上的碟交换一下,最后再输出一下在盒子里面的碟的编号即可。
Code
int n, m, a[100007], x;
int main() {
//This program is written in Windows 10 by Eason_AC
getint(n), getint(m);
_for(i, 0, n) a[i] = i;
while(m--) {
getint(x);
_for(i, 1, n) if(a[i] == x) {swap(a[0], a[i]); break;}
}
_for(i, 1, n) writeint(a[i]), puts("");
return 0;
}
最新文章
- 如何在Visual Studio 2012中发布Web应用程序时自动混淆Javascript
- html中select标签根据枚举获得值的总结
- java中异常注意问题(发生在多态是的异常问题)
- Gym 100917J---dir -C(RMQ--ST)
- memcached与.NET的融合使用(一)
- Jenkins进阶系列之——05FTP publisher plugin插件
- Git 一些日常使用积累
- WebStorm快捷键收集
- 封装Unity3d的dll时的经验总结
- 工厂方法模式(java 设计模式)
- java foreach循环为什么不能赋值
- boost signal2 slot_base
- 转载:做Java开发这一年 (火龙果软件)
- MyEclipse解决SVN同步冲突问题conflict in the working copy obstructs the current operation
- WaitForSingleObject函数
- T-SQL动态查询(1)——简介
- markdown特殊符号语法
- Python列表详解
- 每日英语:A Buying Guide to Air-Pollution Masks
- 第二十四天- 模块导入 import from xxx import xxx
热门文章
- No 'Access-Control-Allow-Origin' header: 跨域问题踩坑记录
- linux下vim的安装与配置(centos)
- 【模板】缩点(Tarjan算法)/洛谷P3387
- 使用GitHub Action进行打包并自动推送至OSS
- A Child's History of England.16
- A Child's History of England.18
- Qt5的安装和编译
- HTML5 基础内容(元素/属性/格式化)
- 【leetcode】563. Binary Tree Tilt
- C++ 德才论