#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,k;
int a[500010];
int st;
string s;
signed main(){
    cin>>n>>m;
    for(int i=0;i<n;i++) a[i]=i+1;
    for(int i=1;i<=m;i++){
        cin>>s;
        int d=0,cur=0;
        while('0'<=s[cur]&&s[cur]<='9'){ d=d*10+s[cur++]-'0';
        }
 //       cout<<d<<endl;
        int o=s[cur]-'a';
        if(o==0){
            d%=n;
            st=(st-d+n)%n;
        }
        else{
            d%=3;
            int x=st,y=(st+1)%n,z=(st+2)%n;
            int w=a[x],q=a[y],p=a[z];
            if(d==1) a[x]=p,a[y]=w,a[z]=q;
            if(d==2) a[x]=q,a[y]=p,a[z]=w;
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[st]<<' ';
        st=(st+1)%n;
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n, T, k, s;
struct node {
    int x, y;
} a[100010];
struct edge {
    int u, v;
    double r;
    bool operator<(const edge &rhs) const { return r > rhs.r; }
};
bool cmp(node x, node y) { return x.x < y.x; }
priority_queue<edge> q;
int vis[1010];
double calc(int i, int j) { return 1.00 * (a[i].y - a[j].y) / (a[i].x - a[j].x); }
int main() {
    cin >> T;
    while (T--) {
        cin >> n >> k;
        s = 0;
        for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
        memset(vis, 0, sizeof(vis));
        sort(a + 1, a + n + 1, cmp);
        for (int i = 1; i <= n; i++) {
            if (s < k) {
                s++;
                for (int j = 1; j < i; j++)
                    if (!vis[j])
                        q.push({ i, j, calc(i, j) });
                continue;
            }
            for (int j = 1; j < i; j++)
                if (!vis[j])
                    q.push({ i, j, calc(i, j) });
            if (q.top().u == i) {
                vis[i] = 1;
                continue;
            }
            while (vis[q.top().u] || vis[q.top().v]) q.pop();
            if (q.top().u != i)
                vis[q.top().u] = 1, q.pop();
        }
        while (vis[q.top().u] || vis[q.top().v]) q.pop();
        printf("%.6lf\n", q.top().r);
        while (!q.empty()) q.pop();
    }
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
int T, n, m, ans, maxid;
int vis[4010];
int calc(int s, int x) {
    int t = n / x + (s == x ? 0 : 1);
    while (s + t * x - x > n) t--;
    return (s + t * x) % n % x;
}
int find(int s, int t, int ts, int x) {  // s为B,t为A
    int l = 1, r = ts, ans = ts + 1;
    while (l <= r) {
        int mid = l + r >> 1;
        int st = s + mid - 1;
        int tt = t + (mid - 1) * x;
        if (tt > st) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    return ans;
}
int main() {
    cin >> T;
    while (T--) {
        cin >> n >> m;
        ans = 0;
        maxid = 1;
        for (int i = 2, sum, cnt; i <= m; i++) {
            memset(vis, 0, sizeof(vis));
            vis[0] = 1;
            cnt = 1;
            sum = 0;
            //            cout<<i<<endl;
            for (int j = i; !vis[j]; j = calc(j, i)) {
                int t = n / i + 1, ed = (t - 1) * i + j;
                if (ed > n) {
                    ed -= i;
                    t--;
                }
                //               if(j==i) t++;
                int len = t - find(cnt, j, t, i) + 1;
                int tt = j + (find(cnt, j, t, i) - 1) * i;
                sum += (tt + tt + (len - 1) * i) * len / 2;
                //                cout<<j<<' '<<sum<<' '<<cnt<<' '<<find(cnt,j,t,i)<<endl;
                cnt += t;
                vis[j] = 1;
            }
            //            cout<<sum<<' '<<cnt<<endl;
            if (sum > ans)
                ans = sum, maxid = i;
        }
        cout << maxid << endl;
    }
}
posted on 2024-09-08 11:19  Grylls_117  阅读(6)  评论(0编辑  收藏  举报