Problem C 链表
Description
Input
Output
Sample Input
Sample Output
#include <iostream>
#include <cstring>
#include <list>
const int maxn=5000+5;
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
int n, a[maxn];
memset(a, 1, sizeof(a));
scanf("%d",&n);
for (int i = 1; i <= n; i++)
a[i] = i;
int k = n;
int loge = 2;
while (k > 3)
{
int q = 0;
if (loge == 2)
{
for (int i = 1; i <= n; i++)
if (a[i] != 0 && ++q == 2)
{
q = 0;
a[i] = 0;
k--;
}
loge = 3;
}
else
{
for (int i = 1; i <= n; i++)
if (a[i] != 0)
{
if (a[i] != 0 && ++q == 3)
{
q = 0;
a[i] = 0;
k--;
}
}
loge = 2;
}
}
loge = 1;
for (int i = 1; i <= n; i++)
if (a[i] != 0)
if (loge)
{
cout << i;
loge = 0;
}
else
cout << ' ' << i;
cout << endl;
}
return 0;
}
Problem C 链表的更多相关文章
- josephus Problem 中级(使用数组模拟链表,提升效率)
问题描写叙述: 在<josephus Problem 0基础(使用数组)>中.我们提出了一种最简单直接的解决方式. 可是,细致审视代码之后.发现此种方案的效率并不高,详细体如今.当有人出局 ...
- Problem UVA12657-Boxes in a Line(数组模拟双链表)
Problem UVA12657-Boxes in a Line Accept: 725 Submit: 9255 Time Limit: 1000 mSec Problem Description ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- Problem E: 用链表实现约瑟夫环
Description 你听说过约瑟夫问题吗?问题大致如下:首先n个人围成一个圈,标记为1到n号.接着,从1号开始报数(从1开始),然后2号报数,然后3号...当有人报到到m时,这个人就要踢出比赛,然 ...
- Problem A: C语言习题 链表建立,插入,删除,输出
#include<stdio.h> #include<string.h> #include<stdlib.h> typedef struct student { l ...
- [LeetCode] Odd Even Linked List 奇偶链表
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...
- [LeetCode] Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- [LeetCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- [LeetCode] Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树
Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...
随机推荐
- Android开发面试经——5.常见面试官提问Android题①
版权声明:本文为寻梦-finddreams原创文章,请关注:http://blog.csdn.net/finddreams 关注finddreams博客: http://blog.csdn.net/f ...
- Linux配置全局环境变量的方法
总结3种方法: 1.修改/etc/profile 1.1 :首先在此文件中设置环境变量; 1.2:export 设置好的环境变量. #view /etc/profile export ...
- 青云的机房组网方案(简单+普通+困难)(虚树+树形DP+容斥)
题目链接 1.对于简单的版本n<=500, ai<=50 直接暴力枚举两个点x,y,dfs求x与y的距离. 2.对于普通难度n<=10000,ai<=500 普通难度解法挺多 ...
- intel simd 资料
http://www.cnblogs.com/zyl910/archive/2012/04/26/md00.html https://software.intel.com/sites/landingp ...
- 销售 >> 当今社会生产力最大的源泉为 >>自助服务 与推销员随之消失
销售可能是变化最大的企业职能.比如,经济学家喜欢提出陷阱问题“什么概念或者想法成为当今社会生产力最大的源泉?” 大多数人回答计算机, 正确的回答是自助服务与推销员随之消失 ...
- testng标签运行顺序
testng的annotations运行顺序为: @BeforeSuite @BeforeTest @BeforeClass @BeforeMethod @AfterMethod @AfterClas ...
- 用NAN简化Google V8 JS引擎的扩展
通过C++扩展Google V8 JS引擎的文章很多,Google V8 JS带的例子也容易明白.但是大部分文章都是Hello World型的,真正使用时发现处处是坑.扩展V8最经典的例子就是node ...
- 5.6 TestNg的使用
Java语言编写的WebDriver测试程序通常使用单元测试框架运行.TestNG单元测试框架比JUnit单元测试框架更强大,它提供了更多的扩展功能.目前很大一部分自动化测试工程师已经开始 ...
- hdu 2473 Junk-Mail Filter (并查集之点的删除)
Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Reverse Linked List II [LeetCode]
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...