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 ...
随机推荐
- stl中的空间配置器
一般我们习惯的c++内存配置如下 class Foo { ... }; Foo* pf = new Foo; delete pf; 这里的new实际上分为两部分执行.首先是先用::operator n ...
- [Locked] Walls and Gates
Walls and Gates You are given a m x n 2D grid initialized with these three possible values. -1 - A w ...
- centos 安装node js环境
node.js支持多种平台安装,其中Win平台安装比较简单,下面重点讲解下Linux平台的安装步骤.本文以CentOS平台为实例,不准备讲 解采取源码编译安装方式,而是采取在node.js网站下载已经 ...
- AngularJS $on $broadcast $emit
如何在作用域之间通信呢? 1.创建一个单例服务,然后通过这个服务处理所有子作用域的通信. 2.通过作用域中的事件处理通信.但是这种方法有一些限制:例如,你并不能广泛的将事件传播到所有监控的 ...
- 分布式系统状态下redis存储asp.net session使用第三方Providers驱动
https://github.com/ServiceStack/ServiceStack.Redis (redis客户端组件) 注:redis服务端在windows不太稳定,一般部署在Linux下. ...
- undo损坏故障恢复(二)ORA-01092,ORA-00604,ORA-01110
undo 故障诊断与恢复(二) 今天是2013-09-01,目前困扰我将近一周的问题,终于解决了,我非常感谢帮助我的朋友,也非常感谢管我要钱然后替我解决问题的朋友(我没采用).这更激发了我一定要解决这 ...
- js中return false,return,return true的使用方法及区别
起首return作为返回keyword,他有下面两种返回体式格式 1.返回把握与函数成果 语法为:return 表达式; 语句停止函数履行,返回调用函数,而且把表达式的值作为函数的成果 2.返回把握无 ...
- Slow Server? This is the Flow Chart You're Looking For--reference
Your high-powered server is suddenly running dog slow, and you need to remember the troubleshooting ...
- C/C++ Linux 程序员必须了解的 10 个工具
1. 基本命令http://mally.stanford.edu/~sr/computing/basic-unix.htmlhttp://pangea.stanford.edu/computing/u ...
- HDU 5211 筛法求约数
给出n个数a1,a2...an,定义函数 f[i]=j,(i<j),表示aj mod ai=0 的最小j,其中j大于i,如果不存在这样的数,则f[i]=0 求n个数所有f[]值的和 先用筛法o( ...