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 ...
随机推荐
- [JAVA关键字] synchronized
synchronized, Example: public synchronized void XXX() {} 参考 http://wenku.baidu.com/link?url=ecb1Zivf ...
- [Locked] Zigzag Iterator
Zigzag Iterator Given two 1d vectors, implement an iterator to return their elements alternately. Fo ...
- Gridview实现银行选择列表
[MainActivity.java] package com.example.activitydemo; import android.os.Bundle; import android.view. ...
- php 自定义求数组差集,效率比自带的array_diff函数还要快(转)
<?phpfunction array_different($array_1, $array_2) { $array_2 = array_flip($array_2); //将数组键值调换 fo ...
- TCP/IP源码(59)——TCP中的三个接收队列
http://blog.chinaunix.net/uid-23629988-id-3482647.html TCP/IP源码(59)——TCP中的三个接收队列 作者:gfree.wind@gmai ...
- GCOV 使用用例
1.GCOV查看arm-linux代码覆盖率 一. 关于gcov工具 gcov伴随gcc 发布.gcc编译加入-fprofile-arcs -ftest-coverage 参数 ...
- qt 关于内存泄漏的检测
Qt 关于内存泄露的检测: 收藏人:guitarhua 2012-02-10 | 阅: 转: | 来源 | 分享 Qt 关于内存泄露的检测:工具篇 ...
- ubuntu12.10中没有/etc/inittab文件探究
1. 我们首先来看一下Linux系统开机启动过程: Ubuntu是Linux系统的衍生系统,其开机启动过程与上图相差不大,但是随着系统的不断发展,终究还是有不同的地方,下面,我们来了解一下Ubuntu ...
- Getting Started with the NDK
The Native Development Kit (NDK) is a set of tools that allow you to leverage C and C++ code in your ...
- 大牛对ACM入门菜鸟的一些话
首先就是我为什么要写这么一篇日志.原因很简单,就是因为前几天有个想起步做ACM人很诚恳的问我该如何入门.其实就现在而言,我并不是很想和人再去讨论这样的话题,特别是当我发现我有很多的东西要学的时候,我实 ...