ZOJ-1088
来源:互联网 发布:非农数据大于预期 编辑:程序博客网 时间:2024/05/16 00:30
约瑟环,纯模拟硬搞的,据说有方法可以直接算,表示不会。。提交了两次,中间把步数优化了一下,原先是直接用m去数,其实可以用m%total步数去数,但这里容易出错,当m%total=0时,要处理一下,用total去数
#include<stdio.h>#include<stdlib.h>struct Building;typedef struct Building *Node;struct Building{int number;Node next;};int main(){int n;while (scanf("%d", &n), n){int i,m;Node *array = malloc(n * sizeof(Node));for (i = 0; i < n; i++)array[i] = malloc(sizeof(struct Building));for (m = 1;; m++){for (i = 0; i < n - 1; i++){array[i]->number = i + 1;array[i]->next = array[i + 1];}array[n - 1]->number = n;array[n - 1]->next = array[0];Node curr = array[0];Node prev = array[n - 1];int total = n;while (total != 1){prev->next = curr->next;curr = curr->next;total--;int step = m % total ? m % total : total;for (i = 0; i < step - 1; i++){prev = curr;curr = curr->next;}}if (curr->number == 2)break;}printf("%d\n", m);for (i = 0; i < n; i++)free(array[i]);free(array);}return 0;}
0 0
- zoj 1088
- zoj 1088
- zoj 1088
- ZOJ-1088
- zoj 1088
- zoj 1088 System Overload
- zoj-1088-System Overload
- zoj 1088 System Overload
- zoj 1088 System Overload
- zoj 1088 约瑟夫环
- ZOJ 1088 System Overload
- zoj--1088--System Overload
- ZOJ 1088 System Overload
- zoj 1088 System Overload
- ZOJ 1088 System Overload
- ZOJ 1088 System Overload
- ZOJ
- ZOJ
- java中枚举
- C++中的typeid
- C++中的typename
- 【安卓笔记】notification使用
- C++中的using
- ZOJ-1088
- 黑程序员_Java基础加强(中)_JavaBean,注解,泛型_27
- poj 3616 Milking Time DP
- 你的人生是在挑水还是在挖井
- 用Matlab来将分层制造过程中G代码所表示的单层的加工路径显示出来
- poj1008
- android 游戏模拟器源码大全。
- jsp读取properties文件
- poj1046