• CF1481B New Colony


    B. New Colony

    本题我在 14min 时通过,当时只有 647 人通过。

    本题 \(k\) 很大,其实是个纸老虎。我们想最简单的,如果有一次我的石头滚到了 \(n+1\) 处,那么下一个,还会滚到 \(n+1\) 处,因此我们只需要一直模拟,直到有石头滚到 \(n+1\) 时,退出循环,答案为 \(-1\)。若 \(k\) 次前,没有滚到 \(n+1\) 处,把模拟得出的答案输出即可,可以证明,时间复杂度为 \(O(\sum hn)\)

    //Don't act like a loser.
    //This code is written by huayucaiji
    //You can only use the code for studying or finding mistakes
    //Or,you'll be punished by Sakyamuni!!!
    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    
    int read() {
    	char ch=getchar();
    	int f=1,x=0;
    	while(ch<'0'||ch>'9') {
    		if(ch=='-')
    			f=-1;
    		ch=getchar();
    	}
    	while(ch>='0'&&ch<='9') {
    		x=x*10+ch-'0';
    		ch=getchar();
    	}
    	return f*x;
    }
    
    const int MAXN=100+10;
    
    int n,h[MAXN],k;
    
    signed main() {
    	int t=read();
    	while(t--) {
    		n=read();k=read();
    		for(int i=1;i<=n;i++) {
    			h[i]=read();
    		}
    		h[n+1]=0;
    		
    		bool flag=1;
    		int pos;
    		while(k--&&flag) {
    			pos=1;
    			while(pos<=n&&h[pos]>=h[pos+1]) {
    				pos++;
    			}
    			h[pos]++;
    			if(pos==n+1) {
    				flag=0;
    				pos=-1;
    			}
    		}
    		cout<<pos<<endl;
    	}
    	return 0;
    }
    
    
    
  • 相关阅读:
    JAVA假期第五天2020年7月10日
    JAVA假期第四天2020年7月9日
    JAVA假期第三天2020年7月8日
    JAVA假期第二天2020年7月7日
    JAVA假期第一天2020年7月6日
    CTF-sql-group by报错注入
    CTF-sql-order by盲注
    CTF-sql-sql约束注入
    CTF-sql-万能密码
    X-Forwarded-for漏洞解析
  • 原文地址:https://www.cnblogs.com/huayucaiji/p/CF1481B.html
Copyright © 2020-2023  润新知