P1088-火星人

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 4 const int maxn = 10009;
 5 typedef long long ll;
 6 int N,M;
 7 int a[maxn];
 8 inline ll read()
 9 {
10     ll ans = 0;
11     char ch = getchar(), last = ' ';
12     while(!isdigit(ch)) last = ch, ch = getchar();
13     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
14     if(last == '-') ans = -ans;
15     return ans;
16 }
17 inline void write(ll x)
18 {
19     if(x < 0) x = -x, putchar('-');
20     if(x >= 10) write(x / 10);
21     putchar(x % 10 + '0');
22 }
23 
24 int main()
25 {
26     N = read(),M = read();
27     _for(i,0,N)
28         a[i] = read();
29     do
30     {
31         if(M==0)
32             break;
33         M --;
34     }while(next_permutation(a,a+N));
35     _for(i,0,N)
36     {
37         write(a[i]);
38         if(i!=N-1)
39         printf(" ");
40     }
41     return 0;
42 }

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 5 typedef long long ll;
 6 using namespace std;
 7 ll a[10003];
 8 ll rnt[10003];
 9 int vis[10003];
10 int m,n;
11 inline ll read()
12 {
13     ll ans = 0;
14     char ch = getchar(), last = ' ';
15     while(!isdigit(ch)) last = ch, ch = getchar();
16     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
17     if(last == '-') ans = -ans;
18     return ans;
19 }
20 inline void write(ll x)
21 {
22     if(x < 0) x = -x, putchar('-');
23     if(x >= 10) write(x / 10);
24     putchar(x % 10 + '0');
25 }
26 int main()
27 {
28     n = read(),m = read();
29     ll res = 0;
30     _for(i,0,n)
31         a[i] = read();
32     
33     _for(i,0,n)
34     {
35         ll tsum = 0;
36         _for(j,0,i+1)
37             if(a[j] <= a[i])
38                 tsum ++;
39         rnt[i] = a[i]-tsum;
40     }
41     rnt[n-1] += m;
42     for(int i = n-1;i > 0;i--)
43     {
44         rnt[i-1] += rnt[i]/(n-i);
45         rnt[i] %= n-i;
46     }
47     
48     memset(vis,0,sizeof(vis));
49     _for(i,0,n)
50     {
51         rnt[i] ++;
52         int j;
53         for(j = 1;j <= n;j ++)
54         {
55             if(vis[j])
56                 continue;
57             rnt[i] --;
58             if(!rnt[i])    
59                 break;
60         }
61         vis[j] = 1;
62         printf("%d ",j);
63     }
64     return 0;
65 }

 

转载于:https://www.cnblogs.com/Asurudo/p/11259014.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值