HDU1276(士兵队列训练模拟与链表)
HDU1276
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
#include<iostream>
using namespace std;
int main()
{
int i,t,n,p;
int f=;
int a[];
cin>>t;
while(t--)
{
int q;//定义整型变量,n赋值给q
cin>>n;
q=n;
for(i=; i<=n; i++)
a[i]=i;
while(q>) //判断条件
{ p=;
for(i=; i<=n; i++)
{
if(a[i]==)
continue;
else
p++;
if(p==)
{
a[i]=;
f+=; //统计出列士兵个数
p=;
}
}
q=q-f;
if(q<=)break;
p=;
f=; //注意每次归0
for(i=; i<=n; i++)
{
if(a[i]==)
continue;
else
p++;
if(p==)
{
a[i]=;
f+=;
p=;
}
}
q=q-f;
}
p=;
for(int i=; i<=n; i++)
{
if(a[i]==)
continue;
else
{
p+=;
if(p==q)
cout<<a[i]<<endl;
else
cout<<a[i]<<" ";
}
}
}
return ; }
这个才是正确的,错误的地方有标记
#include<iostream>
using namespace std;
int main()
{
int i,t,n,p;
int a[];
cin>>t;
while(t--)
{
int q;//定义整型变量,n赋值给q
cin>>n;
q=n;
for(i=; i<=n; i++)
a[i]=i;
while(q>) //判断条件
{
int f=;//这里!!
p=;
for(i=; i<=n; i++)
{
if(a[i]==)
continue;
else
p++;
if(p==)
{
a[i]=;
f+=; //统计出列士兵个数
p=;
}
}
q=q-f;
if(q<=)break;
p=;
f=; //注意每次归0
for(i=; i<=n; i++)
{
if(a[i]==)
continue;
else
p++;
if(p==)
{
a[i]=;
f+=;
p=;
}
}
q=q-f;
}
p=;
for(int i=; i<=n; i++)
{
if(a[i]==)
continue;
else
{
p+=;
if(p==q)
cout<<a[i]<<endl;
else
cout<<a[i]<<" ";
}
}
}
return ; }
参考小云博客:链表使用,与模拟还是很相像的
#include"iostream"
#include"list"
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
list<int> s;
if(n==) cout<<<<endl;
else
{
for(int i=; i<=n; i++)
s.push_back(i);
list<int>::iterator it,ip;//链表遍历迭代器
int f=;
int flag=s.size();
while(flag>)
{
for(it=s.begin(); it!=s.end();)
{
if(f==)
{
f=;
ip=it;
it++;
s.erase(ip); //抹除操作
flag--;
}
else
{
f++;
it++;
}
}
f=;
if(flag<=) break;
for(it=s.begin(); it!=s.end();)
{
if(f==)
{
f=;
ip=it;
it++;
s.erase(ip);
flag--;
}
else
{
f++;
it++;
}
}
f=;
if(flag<=) break;
}
int w=;
for(it=s.begin(); it!=s.end(); it++)
{
cout<<(*it); //注意输出格式
w++;
if(w<=flag-) cout<<' ';
}
cout<<endl;
}
}
return ;
}
HDU1276(士兵队列训练模拟与链表)的更多相关文章
- hdu1276士兵队列训练问题[简单STL list]
目录 题目地址 题干 代码和解释 题目地址 hdu1276 题干 代码和解释 本题使用了STL中的list,STL的list是双向链表.它的内存空间不必连续,通过指针来进行数据的访问,高效率地在任意地 ...
- (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数<=3,输出剩下的人 )
题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 1276 士兵队列训练问题(模拟)
原题代号:HDU 1276 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1276 题目原题: 士兵队列训练问题 Time Limit: 2000/10 ...
- hdoj 1276 士兵队列训练问题【模拟】
士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- A - 士兵队列训练问题
A - 士兵队列训练问题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- Problem UVA12657-Boxes in a Line(数组模拟双链表)
Problem UVA12657-Boxes in a Line Accept: 725 Submit: 9255 Time Limit: 1000 mSec Problem Description ...
- UVa 12657 Boxes in a Line(数组模拟双链表)
题目链接 /* 问题 将一排盒子经过一系列的操作后,计算并输出奇数位置上的盒子标号之和 解题思路 由于数据范围很大,直接数组模拟会超时,所以采用数组模拟的链表,left[i]和right[i]分别表示 ...
- 【ACM】hdu_1276_士兵队列训练问题_201308131032
士兵队列训练问题Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- HDU 1276 士兵队列训练问题(队列)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1276 题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Othe ...
随机推荐
- Event 元标签中的代码提示问题
自定的事件可以利用Event元标签在支持该事件的类里面做绑定,绑定后FlashBuilder会有代码提示,以提示该类支持的事件类型 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...
- ie8下$(document).on('mouseover mouseout','ul li',function(){})的bug
$(document).on('mouseover mouseout','ul li',function(){ if (event.type == 'mouseover') { c ...
- winform程序中将控件置于最顶层或最底层的方法
有时,我们可能动态的添加控件,并准备将其置于对顶层或最底层.实现的方法有两个: 一种方法是在WinForm窗体中使用Controls控件集的SetChildIndex方法,该方法将子控件设定为指定的索 ...
- Android Touch系统简介(二):实例详解onInterceptTouchEvent与onTouchEvent的调用过程
上一篇文章主要讲述了Android的TouchEvent的分发过程,其中有两个重要的函数:onInterceptTouchEvent和onTouchEvent,这两个函数可被重装以完成特定的逻辑.on ...
- 监控 Linux 性能的 18 个命令行工具
http://www.oschina.net/translate/command-line-tools-to-monitor-linux-performance 1.Top-Linux进程监控 Lin ...
- Qt 学习之路 :可视化显示数据库数据
前面我们用了两个章节介绍了 Qt 提供的两种操作数据库的方法.显然,使用QSqlQuery的方式更灵活,功能更强大,而使用QSqlTableModel则更简单,更方便与 model/view 结合使用 ...
- Valgrind简介:
Valgrind是动态分析工具的框架.有很多Valgrind工具可以自动的检测许多内存管理和多进程/线程的bugs,在细节上剖析你的程序.你也可以利用Valgrind框架来实现自己的工具. Valgr ...
- How to load jars residing over NFS in JBossAS7 classpath ? --reference
In this article we will discuss how can we load jars residing over NFS in JBoss AS-7 classpath. In s ...
- Java基础知识强化之IO流笔记05:try...catch...finally包含的代码是运行期的
1. 代码示例: 上面看到的第13行: Date d = null;(这里必须初始化) 第14~20行使用try...catch...finally包含代码,这里的代码已经变成运行期代码.此时我们 ...
- 进阶篇,第二章:MC与Forge的Event系统
<基于1.8 Forge的Minecraft mod制作经验分享> 这一章其实才应该是第一章,矿物生成里面用到了Event的一些内容.如果你对之前矿物生成那一章的将算法插入ORE_GEN_ ...