zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    Unity物理系统随记
    Unity相机跟随小结
    unity制作赛车游戏
    动态编程
    C#-特性,反射,动态编程
    BASE64加解密
    idea快捷键
    git安装和git命令:全局设置用户名邮箱配置
    基于Node.js+MySQL开发的开源微信小程序商城(微信小程序)部署环境
    微信小程序开发入门(一),Nodejs搭建本地服务器
  • 原文地址:https://www.cnblogs.com/Asurudo/p/11259014.html
Copyright © 2011-2022 走看看