【HDU】2020暑期杭电多校第7场解题报告(更新中)

1009:Increasing and Decreasing

下面是AC代码:

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)    
#define T int t ;cin >> t;while(t--)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
inline ll gcd(ll a,ll b){return b == 0? a:gcd(b, a % b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-11;
ll a[maxn] ;
const ll mod = 1e9 + 7;
int main(){
    T{
        memset(a,0,sizeof a) ;
        ll n , x, y ;
        ll b , c ;
        scanf("%lld%lld%lld",&n,&x,&y) ;
        b = n / y ;
        c = n - b * y ;
        if(x+y>n+1||b+1>x&&c||b>x||x==1&&y!=n||y==1&&x!=n){    
            printf("NO\n") ;
            continue ;
        }
        if(x == 1 &&y == n){
            printf("YES\n") ;
            for(int i = n ; i >=1 ; i--){
                if(i!= n) printf(" ") ;
                printf("%d",i) ;
            }
            printf("\n") ;
            continue ;
        }
        else if(y == 1 &&x == n){
            printf("YES\n") ;
            for(int i = 1 ; i <= n ; i++){
                if(i != 1) printf(" ") ;
                printf("%d",i) ;
            }
            printf("\n") ;
            continue ;
        }
        else{
            printf("YES\n") ;
            while(x > b + c) b-- , c += y ;
            if(c == 0){
                  int times = 1 ;
                  while(times <= b){
                      for(int i = times * y ; i > (times - 1) * y ; i--)
                      if(times == b && i == times * y - y + 1 )
                          printf("%d",i) ;
                      else 
                          printf("%d ",i) ;
                      times++ ;
                }
                printf("\n") ;
              }
              else{
                  for(int i = 1 ; i <= x - b - 1 ; i++)
                      printf("%d ",i) ;
                  for(int i = c ; i >= x - b ; i--)
                      printf("%d ",i) ;
                  int times = 1 ;
                  while(times <= b){
                      for(int i = times * y + c ; i > (times - 1) * y + c ; i--)
                          if(times == b && i ==c + times * y - y +1)
                              printf("%d",i) ;
                      else 
                          printf("%d ",i) ;
                      times++ ;
                }
                printf("\n") ;
           }
            
        }
    }
    return 0 ;
}

猜你喜欢

转载自blog.csdn.net/zcmuhc/article/details/107943390