zoukankan      html  css  js  c++  java
  • Codeforces 1256C Platforms Jumping

    思路:

    cf自带的题解,思路很清晰:

    This problem has a very easy idea but requires terrible implementation. Firstly, let’s place all platforms as rightmost as we can. Thus, we will have the array, in which the first n−∑i=1mci elements are zeros and other elements are 1, 2, …, m.
    Now, let’s start the algorithm. Firstly, we need to jump to the position d or less. If we could jump to the position d then we don’t need to jump to some position to the left from d. But if we cannot do it, let’s take the leftmost platform to the right from the position d and move it in such a way that its left border will be at the position d. Now we can jump to the position d and then jump by 1 right to reach the position d+c1−1. Let’s repeat the same algorithm and continue jumping.
    If after some move we can jump to the position at least n+1then we are done.
    Time complexity: O(n2)but I’m sure it can be implemented in O(nlogn) or O(n).

    整体思路就是贪心。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define rp(i,n) for(int i=0;i<n;i++)
    #define rpn(i,n) for(int i=1;i<=n;i++)
    const int MAX_N=1005;
    int c[MAX_N];
    int rv[MAX_N];
    int main(){
    	int n,m,d,suml;
    	cin>>n>>m>>d;
    	rpn(i,m) cin>>c[i];
    	for(int i=m,pos=n;i>=1;i--){
    		for(int j=0;j<c[i];j++){
    			rv[pos-j]=i;
    		}
    		pos-=c[i];
    	}
    	int pos=0,flag=false;
    	for(int i=1;i<=m;i++){
    		pos+=d;//往前跳d 
    		if(pos>n||rv[pos]){flag=true;break;}
    		int plat=pos+1;
    		while(!rv[plat]) plat++;
    		int len=c[rv[plat]];
    		for(int j=0;j<len;j++){
    			swap(rv[pos+j],rv[plat+j]);
    		}
    		pos+=len-1;
    	}
    	if(pos+d>n||flag){
    		cout<<"YES
    ";
    		cout<<rv[1];
    		for(int i=2;i<=n;i++) cout<<' '<<rv[i]; 
    	}else cout<<"NO";
    	return 0;
    }
    
  • 相关阅读:
    Git本地操作2
    Blast在windows下的使用过程
    和为T
    出现次数最多的整数
    蓝桥杯 未名湖边的烦恼 java
    蓝桥杯数字三角形 java
    ①①将线性拉伸
    ⑩把线型对象转平面对象
    ⑨矩形
    ⑧建立样条:(样条也能够被拉伸)
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308899.html
Copyright © 2011-2022 走看看