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 ...
随机推荐
- bzoj 1560 [JSOI2009]火星藏宝图(DP)
1560: [JSOI2009]火星藏宝图 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 647 Solved: 309[Submit][Status ...
- bzoj 2324 [ZJOI2011]营救皮卡丘(floyd,费用流)
2324: [ZJOI2011]营救皮卡丘 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1777 Solved: 712[Submit][Stat ...
- Windows Shell Extension 系列文章
Windows Shell Extension 系列文章 http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-C ...
- [转]C服务端与java客户端的socket通信注意事项
http://blog.csdn.net/gaoxin1076/article/details/7671752 Socket网络通讯开发总结之:Java 与 C进行Socket通讯 注意以下问题: 1 ...
- angularJS 服务二
$http服务 一 介绍 AngularJS为我们提供了很多种服务,$http用于发送http请求,动态的请求数据.我们可以使用内置的$http服务直接同外部进行通信.$http服务只是简单的封装了浏 ...
- 【.NET调用Python脚本】C#调用python requests类库报错 'module' object has no attribute '_getframe' - IronPython 2.7
最近在开发微信公众号,有一个自定义消息回复的需求 比如用户:麻烦帮我查询一下北京的天气? 系统回复:北京天气,晴,-℃... 这时候需要根据关键字[北京][天气],分词匹配需要执行的操作,然后去调用天 ...
- 设计模式(二)The Observer Pattern 观察者模式
问题引入 生成一个公告板显示当时的天气状况,当天气状况发生改变的时候公告板能够实时的更新. 模式定义 定义对象之间的一对多的依赖.当一个对象改变状态时,它的全部依赖者都会自己主动收到通知并自己主动更新 ...
- 1小时学Python脚本
如果我们有这么一项任务:简单測试局域网中的电脑是否连通.这些电脑的ip范围从192.168.0.101到192.168.0.200. 思路:用shell编程.(Linux一般是bash而 ...
- 多线程下的NSOperation和NSOperationQueue的使用
多线程下的NSOperation和NSOperationQueue的使用 NSOperation和NSOperationQueue的介绍: NSOperation是Cocoa中的一个抽象类,用来封装单 ...
- Python之路,Day8 - Socket编程进阶
Python之路,Day8 - Socket编程进阶 本节内容: Socket语法及相关 SocketServer实现多并发 Socket语法及相关 socket概念 socket本质上就是在2台 ...