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 ...
随机推荐
- FTP 连接报错
Filezilla 站点管理器=>选中FTP站点=>加密(只使用普通FTP)
- 一步一步实现视频播放器client(二)
实现主体界面: 222.png (64.46 KB, 下载次数: 0) 下载附件 保存到相冊 前天 21:02 上传 比較常见的一种布局.以下几个button.点击后 ...
- sphinx PDF 中文
使用reST撰写文档时,需要分多个文档时,就必须使用sphinx了,sphinx说起来很简单的,但是默认是不是支持中文的.幸好我出生的晚,sphinx现在已经支持xelatex了^_^ 安装 除了pa ...
- 每门课由平时成绩和考试成绩组成,满分为r。现在他知道每门课的平时成绩为ai ,若想让这门课的考试成绩多拿一分的话,小v要花bi 的时间复习,不复习的话当然就是0分。同时我们显然可以发现复习得再多也不会拿到超过满分的分数。为了拿到奖学金,小v至少要花多少时间复习。
遇到问题要常思考为什么,做这道题的时候,要注意给定的数据范围. 第一行三个整数n,r,avg(n大于等于1小于等于1e5,r大于等于1小于等于1e9,avg大于等于1小于等于1e6),接下来n行,每行 ...
- FreeRTOS在神舟IV号开发板的应用demo
下面一个可以直接编译运行的例子,FreeRTOS的版本是V7.1.0,芯片是STM32F107VCT6,使用的开发环境是Keil uVision5. 这里例子创建了四个任务,每个任务控制一个LED的亮 ...
- php开启pathinfo 模式
pathinfo 模式 需要 php.ini 开启下面这个参数 cgi.fix_pathinfo=1 path_info模式:http://www.xxx.com/index.php/模块/方法 ...
- rpm包查看和解压(转)
From:http://www.51testing.com/html/57/28557-205195.html 查看rpm包内容: rpm -qpl *.rpm 解压rpm包: rpm2cpio *. ...
- 解决pod search出来的库不是最新
为了让CocoaPods的引入不显示警告,在Podfile最上方加上: inhibit_all_warnings! pod search 一些第三方SDK,发现并不是最新版本,那是因为你的本地repo ...
- 【LeetCode】Balanced Binary Tree 解题报告
[题目] Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bi ...
- python 基础 1.5 python数据类型(二)--列表常用方法示例
#/usr/bin/python #coding=utf-8 #@Time :2017/10/12 23:30 #@Auther :liuzhenchuan #@File :列表.py lis ...