HDU1276-士兵队列训练问题 (Queue)
2024-10-08 10:27:28
题很简单,STL中queue的基本使用。
#include <bits/stdc++.h>
using namespace std;
int N,num;
int main()
{
scanf("%d",&N);
while (N--) {
scanf("%d",&num);
if (num<=3) {
for (int i=1;i<num;i++) {
printf("%d ",i);
}
printf("%d\n",num);
continue;
}
queue<int>q;
for (int i=1;i<=num;i++) {
q.push(i);
}
int top=num,cnt=1;
while (true) {
// printf("IN\n");
while (cnt<top+1) {
if (cnt%2!=0) {
// printf("%d\n",q.front());
q.push(q.front());
}
q.pop();
cnt++;
}
if (q.size()<=3) {
break;
}
// printf("%d\n",q.size());
top=q.size();
cnt=1;
while (cnt<top+1) {
if (cnt%3!=0) {
// printf("%d\n",q.front());
q.push(q.front());
}
q.pop();
cnt++;
}
if (q.size()<=3) {
break;
}
top=q.size();
cnt=1;
}
while (q.size()>1) {
printf("%d ",q.front());
q.pop();
}
printf("%d\n",q.front());
}
return 0;
}
最新文章
- 修改php.ini以达到 屏蔽错误信息
- Find Minimum in Rotated Sorted Array II
- why does angular js rock
- openVPN使用
- 用Java socket (TCP通信模型)实现一个简单的web 服务器
- php 加载函数 __autoload(), spl_autoload_register()
- 無心插柳的Linux學習者代言人——蔡德明
- 《STL源代码剖析》---stl_alloc.h阅读笔记
- 在magento中定义static block
- wpf mvvm datagrid DataGridTemplateColumn的绑定无效的可能原因之一!
- spring 注解模式 详解
- python继承和多态
- xshell 5中文破解版下载
- OpenEXR的读取机制
- Pandas新建一个DataFrame
- yaf 整理札记
- k8s secret
- 「6月雅礼集训 2017 Day4」寻找天哥
- Mui 选项卡 tab 高度 没有自适应....
- Python如何利用多核处理器
热门文章
- please execute the cleanup command
- (转)KMP算法
- No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor
- 整理收集的一些常用java工具类
- IntelliJ IDEA 2017.3尚硅谷-----创建动态的 Java Web
- 同一域名的ASP.NET网站实现Session共享
- Apache Kafka(五)- Safe Kafka Producer
- Linux - Shell - cut: 低配 awk
- SpringBoot获取http请求参数的方法
- drc实现