解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class 模拟_奥运会开幕式 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int m = scan.nextInt(); // 循环链表创建并且赋值(带头节点) Node head = new Node(0, null); for(int i = n ; i >= 1 ; i--) { Node t = new Node(i, null); t.setNext(head.getNext()); head.setNext(t); if(i == n) { t.setNext(head); } } //删到只剩两个节点为止,其中一个是头节点 Node p = head; Node pre = null; boolean flag = true; for(int i = 0 ; i < n - 1; i++) { for(int j = 0 ; j < m ; j++) { if(flag == true) { if(p.getIndex() == 0) { flag = false; } } pre = p; p = p.getNext(); if(flag == false && p.getIndex() == 0) { pre = p; p = p.getNext(); } } pre.setNext(p.getNext()); } //只剩下头节点和另外一个节点,另外一个节点就是我们要的答案 System.out.println(head.getNext().getIndex()); } } class Node { int index; Node next; public Node(int index, Node next) { super(); this.index = index; this.next = next; } public int getIndex() { return index; } public void setIndex(int index) { this.index = index; } public Node getNext() { return next; } public void setNext(Node next) { this.next = next; } }
0.0分
0 人评分
校门外的树 (C语言代码)浏览:988 |
WU-字符串比较 (C++代码)浏览:824 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:600 |
a+b浏览:452 |
蚂蚁感冒 (C语言代码)浏览:1408 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:569 |
图形输出 (C语言代码)浏览:1019 |
JAM计数法 (C语言代码)浏览:721 |
简单的a+b (C语言代码)浏览:497 |
C二级辅导-温度转换 (C语言代码)浏览:575 |