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 Studio插件整理
GOOD 现在Android的开发者基本上都使用Android Studio进行开发(如果你还在使用eclipse那也行,毕竟你乐意怎么样都行).使用好Android Studio插件能大量的减少我们 ...
- Android布局_相对布局RelativeLayout
一.RelativeLayout(相对布局)概述 RelativeLayout是相对布局控件,它包含的子控件将以控件之间的相对位置或者子类控件相对父类容器的位置的方式排列 二.RelativeLayo ...
- Logger日志级别说明及设置方法、说明 (zhuan)
http://blog.csdn.net/rogger_chen/article/details/50587920 ****************************************** ...
- python类、对象、方法、属性之类与对象笔记
python中一切皆为对象,所谓对象:我自己就是一个对象,我玩的电脑就是对象,坐着的椅子就是对象,家里养的小狗也是一个对象...... 我们通过描述属性(特征)和行为来描述一个对象的.比如家里的小狗, ...
- JSON字符串如何转化成对象?
解析 1.定义:是指将符合 JSON 语法规则的字符串转换成对象的过程. 2.不同的编程语言都提供了解析 JSON 字符串的方法,在这里主要讲解 JavaScript 中的解析方法.主要有三种: 1) ...
- jquery 设置checked="checked"无效,radio未选中。。
jquery 设置checked="checked"无效,radio未选中.. 最好还是使用.prop(),在jQuery1.6版本之前.attr存在一些bug.在1.6之后它会自 ...
- SCCM部署win7操作系统,系统盘为D盘
SCCM部署win7操作系统,系统盘为D盘 1. 系统部署完毕之后是这样的 2.解决方案 解决分发干净Windows7操作系统盘符为”D”的方法也比较简单. 在SCCM管理控制台中,打开”软件库””操 ...
- jquery 全选功能
1.直接全选(复选框名字要统一) <input type="CHECKBOX" id="cbSelectAll" onclick="$('inp ...
- android AutoCompleteTextView和Spinner选中项加亮
package com.example.spinnerexample; import java.util.ArrayList; import java.util.List; import androi ...
- Django数据库设置
设置数据库,创建您的第一个模型,得到一个简单介绍 Django的自动生成管理网站. 数据库设置 现在,打开 mysite / settings.py . 这是一个普通的Python模块 模块级变量代表 ...