The Dole queue,Uva 133

mac2022-06-30  131

这种题目主要考察对函数的调用。

题目网络上都有,直接贴源码,参考解析写的代码,不好轻喷

#include <iostream> #define maxn 25 using namespace std; int n,m,k,a[maxn]; int go(int p,int d,int t) { while(t--) { do { p=(p+d+n-1)%n+1; }while(a[p]==0); } return p; } int main() { while(scanf("%d%d%d",&n,&k,&m) == 3 &&n) { for(int i=1;i<=n;i++) { a[i]=i; } int leave=n; int p1=n,p2=1; while(leave) { p1=go(p1,1,k); p2=go(p2,-1,m); cout<<p1<<" "; leave--; if(p1!=p2) { cout<<p2<<" "; leave--; } a[p1]=a[p2]=0; if(leave)cout<<","; } } return 0; }

 

转载于:https://www.cnblogs.com/agui521/p/7020495.html

最新回复(0)