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 ...
随机推荐
- sql语句语法大全
一.基础 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- ...
- 物料BOM和生产订单BOM的区别
物料BOM和生产订单BOM的区别[@more@] 一般企业生产部在SAP创建生产订单的时候,就会产生一个生产订单BOM,这里的生产订单BOM是读取的物料BOM. 由于其它原因,需要修改成品的某几个零部 ...
- 清理PC垃圾
@echo off pause echo 正在清除系统垃圾文件,请稍等...... del /f /s /q %systemdrive%\*.tmp del /f /s /q %systemdrive ...
- linux笔记:linux系统安装-vmware虚拟机安装
vmware版本:vmware8(百度云里备份了安装程序VMware_Workstation_wmb.zip) vmware软件安装过程: 1.在百度云中下载安装程序压缩包VMware_Worksta ...
- C#综合揭秘——细说多线程(上)
引言 本文主要从线程的基础用法,CLR线程池当中工作者线程与I/O线程的开发,并行操作PLINQ等多个方面介绍多线程的开发. 其中委托的BeginInvoke方法以及回调函数最为常用. 而 I/O线程 ...
- 5.4.2 使用配置启动firefox
1.使用firefox的本地配置加载浏览器 使用本地配置加载浏览器,代码如下. 这样运行后,可以看到firebug等插件都已启动. 练习:假设做性能测试时,需要获取某个状况下的页面网络运行参数.要求完 ...
- css3做的动画
基于放大缩小: http://www.credero.etall.cn/demo/jwtplay/3/content05.html 基于3d: http://www.credero.etall.cn/ ...
- Java基础:多线程
基本概念 程序&线程&进程 程序是一个段可以提供业务功能的代码,它可以包含1个或多个进程.程序在OS上运行时表现为进程对各种资源(CPU,内存,Disk..)的消耗和处理. 进程是OS ...
- 定向转发和重定向实现 <select >下拉表单数据传送
定向转发的特点: (1). 实行转发时浏览器上的网址不变 (如果你这点忽视了,那你就要接受我无尽的鄙视吧! 哇咔咔~~~) (2). 实行转发时 : 只有一次请求. 不信,看这下面的 ...
- IO流--文件处理
import java.io.*; public class io { public static void main(String[] args) { ListDemo(); File dir = ...