Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
141589 刘嘉乐 猴子选大王 C++ 通过 100 23 MS 8056 KB 924 2024-04-06 08:41:13

Tests(7/7):


#include<iostream> #include<string> using namespace std; struct Node{ int pre; int next; }; Node node[1000005]; void insertNode(int p, int x) { int p2 = node[p].next; node[p].next = x; node[x].pre = p; node[x].next = p2; node[p2].pre = x; } void deleteNode(int x) { if (node[x].pre == -1) { return ; } int p1 = node[x].pre; int p2 = node[x].next; node[p1].next = p2; node[p2].pre = p1; node[x].pre = -1; node[x].next = -1; } void traverse(){ int cur = node[0].next; while(cur != 0) { cout << cur <<" "; cur = node[cur].next; } } int main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ node[i].pre = i-1; node[i].next = i+1; } node[1].pre = n; node[n].next = 1; int id = 1,res; for(int i=1;i<=n*m;i++){ int tmp = node[id].next; if(i%m==0){ res = id; deleteNode(id); } id = tmp; } cout<<res<<'\n'; return 0; }


测评信息: