ACM学习历程—HDU 1276 士兵队列训练问题(队列)
Description
Input
Output
Sample Input
Sample Output
题目大意就是一个队列报数,第一次12报数,报到2的出列;第二次123报数,报到3的出列;如此循环往复,直到队列人数不超过3.
这里采用两个队列交替使用,对于12报数的情况,只有报到1的才会入另一个队。
对于123的,自然是报到12的入另一个队。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#define LL long long using namespace std; int n; void work()
{
queue<int> q[];
bool now = ;
int num; for (int i = ; i <= n; ++i)
q[now].push(i); for (;;)
{
if (q[now].size() <= )
break;
num = ;
now = !now;
while (!q[!now].empty())
{
num = num%+;
if (num != )
q[now].push(q[!now].front());
q[!now].pop();
} if (q[now].size() <= )
break;
num = ;
now = !now;
while (!q[!now].empty())
{
num = num%+;
if (num != )
q[now].push(q[!now].front());
q[!now].pop();
}
}
bool flag = false;
while (!q[now].empty())
{
if (flag)
printf(" ");
printf("%d", q[now].front());
q[now].pop();
flag = true;
}
printf("\n");
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times < T; ++times)
{
scanf("%d", &n);
work();
}
return ;
}
ACM学习历程—HDU 1276 士兵队列训练问题(队列)的更多相关文章
- HDU 1276 士兵队列训练问题(队列)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1276 题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Othe ...
- HDU 1276 士兵队列训练问题(模拟)
原题代号:HDU 1276 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1276 题目原题: 士兵队列训练问题 Time Limit: 2000/10 ...
- ACM学习历程—HDU 5512 Pagodas(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...
- ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所 ...
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
- ACM学习历程—HDU 5534 Partial Tree(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题目大意是给了n个结点,让后让构成一个树,假设每个节点的度为r1, r2, ...rn,求f(x ...
- ACM学习历程—HDU 3949 XOR(xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...
- 解题报告:hdu 1276 士兵队列训练问题 - 简单题
Problem Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行 ...
- ACM学习历程—HDU 5317 RGCDQ (数论)
Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more an ...
随机推荐
- kotlin 语言入门指南(一)--基础语法
基于官网的Getting Start的基础语法教程部分,一共三节,这篇是第一节,翻译如下: 基础语法 定义一个包 包的声明必须放在文件头部: package my.demo import java.u ...
- 链接脚本使用一例2---将二进制文件 如图片、MP3音乐、词典一类的东西作为目标文件中的一个段
参考文章: <程序员的自我修养——链接.转载与库> P68 这里介绍两种方法,实现将将一张图片作为二进制可执行程序的一个段,其中第一种方法在我之前的博客中已经有所介绍,不过,那是采用的是交 ...
- C++钩子程序浅析
在网上搜索“键盘记录C++”实现可以找到很多相关文章,我也是照着上面的介绍去研究去试着做的,从懂到不懂.那么为什么有那么多材料我还要去写这样一篇 文章,我想这个是我个人需要关心的问题,我不是那种ctr ...
- c# combobox 绑定枚举方式
建立一个类 : using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- IntelliJ IDEA打可执行jar包
<plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <config ...
- EasyPlayer RTSP播放器对RTSP播放地址url的通用兼容修改意见
问题反馈 最近在线上遇到一位老朋友咨询关于EasyPlayer播放器的事情,大概现象就是分别用EasyPlayer和vlc播放大华摄像机的RTSP流,流地址是:rtsp://admin:admin12 ...
- hdu 4667 Building Fence < 计算几何模板>
//大白p263 #include <cmath> #include <cstdio> #include <cstring> #include <string ...
- protect,internal的区别
protected: 爷爷有一张银行卡,爸爸可以用,儿子也可以用,隔壁老王不可以用(因为老王跟爷爷没有继承关系) internal: 王总有一张银行卡,秘书可以用,经理可以用,王总儿子不可以用(因为银 ...
- 关于spring的bean
1 spring bean的单例和多例 singleton 单例指的是,在需要该bean的地方,spring framework返回的是同一个值. prototype 多例指的是,在需要该bean的地 ...
- Optimizer in SQL - Catalyst Optimizer in Spark SQL
SELECT sum(v) FROM ( SELECT score.id, 100+80+score.math_score+ score.english_score AS v FROM p ...