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 ...
随机推荐
- js 重点 (转载)
- 转!!!Mysql无法创建外键的原因
在Mysql中创建外键时,经常会遇到问题而失败,这是因为Mysql中还有很多细节需要我们去留意,我自己总结并查阅资料后列出了以下几种常见原因. 1. 两个字段的类型或者大小不严格匹配.例如,如果一个 ...
- nfs服务器设置
前段时间重新装了一下Linux系统,结果导致NFS服务器总是挂在不成功,于是粗略学习了一下: NFS服务需要两个软件包: 1.nfs-utiles-* 2.portmap-* nfsd:它是基本的NF ...
- neon汇编,C嵌入汇编
1. Neon-intrics.pdf中的 void vst2q_u16(__transfersize(16) uint16_t * ptr, uint16x8x2_t val);// VST2.16 ...
- Oracle session inactive状态临时表数据未清空问题
问题描述:Oracle数据库,java代码使用某数据库实例,获取connection并在使用结束关闭,而session未销毁,而是状态变为inactive从而导致临时表数据未清空. Oracle临时表 ...
- Git 分支管理是一门艺术
转载: Git 分支管理是一门艺术 1 要确保:团队成员从主分支(master)获得的都是处于可发布状态的代码,而从开发分支(develop)应该总能够获得最新开发进展的代码. 2 "辅助分 ...
- 【转】Linux下XenServer管理工具安装
转载文章 - Linux下XenServer管理工具安装 Xen-Server 6.5 虚拟机安装Linux系统 vmware安装ubuntu12.04嵌套安装xen server(实现嵌套虚拟化) ...
- Python安装BeautifulSoup库(Windows平台下)
简介 参照官网Beautiful Soup4.4.0文档:https://www.crummy.com/software/BeautifulSoup/bs4/doc/ 安装步骤 1.到https:// ...
- $('#checkbox').attr('checked'); 返回的是checked或者是undefined解决办法
$('#checkbox').attr('checked'); 返回的是checked或者是undefined解决办法 <input type='checkbox' id='cb'/> ...
- MVC设计模式(持续更新中)
MVC设计模式--->英文全称为: model(模型) View (视图) Controller(控制) MVC是一种设计思想.这种思想强调实现模型(Model).视图(View)和控制 ...