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 ... 
随机推荐
- Eclipse下导入外部jar包的3种方式 (zhuan)
			http://blog.csdn.net/mazhaojuan/article/details/21403717 ******************************************* ... 
- 第二章 Python基本元素:数字、字符串和变量
			Python有哪些内置的数据类型: True False #布尔型 42 100000000 #整型 3.14159 1.0e8 #浮点型 abcdes #字符串 2.1 变量.名字和对象 pytho ... 
- 在腾讯云上创建您的SQL Cluster(3)
			版权声明:本文由李斯达原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/250 来源:腾云阁 https://www.qclo ... 
- python核心编程第六章练习6-8
			6-8.列表.给出一个整型值,返回代表该值得英文,比如输入89会返回“eight-nine”.附加题:能够返回符合英文语法规律的新式,比如输入89会返回“eighty-nine”.本练习中的值假定在0 ... 
- 设置segue跳转页面
			第二种是利用ViewController与ViewController之间,拖拽添加segue 方法中提到的设置segue的identifier界面 在.h文件中声明 - (IBAction)goto ... 
- 制作Aspose CHM文档的过程记录
			欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ... 
- openmpi出现Segmentation Fault而终止运算
			欢迎关注我的社交账号: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://gith ... 
- java复用和传参
			java复用和传参的三种方法总结: (1) 直接在一个类中调用函数 : 1 package test1; 2 3 public class a 4 { 5 public static void get ... 
- 背景大图隔几秒切换(非轮播,淡入淡出)--变形金刚joy007 项目总结
			工作日想了好久,周日回家才想出来的... 图片切换(非轮播,淡入淡出) 1.切换2.停止 <html> <head> <meta content="text/h ... 
- 关于java中JButton的样式设置(的一些我们应该知道的函数)(转)
			1. 对JButton大小的设置 ——因为JButen是属于小器件类型的,所以一般的setSize不能对其惊醒大小的设置,所以一般我们用 button.setPreferredSize(new Dim ... 
