zoukankan      html  css  js  c++  java
  • 最近做的题

    2021女生赛B

    点击查看代码
    // Problem: B. 攻防演练
    // Contest: Codeforces - 2021年中国大学生程序设计竞赛女生专场
    // URL: https://codeforces.com/gym/103389/problem/B
    // Memory Limit: 512 MB
    // Time Limit: 1000 ms
    // 
    // Powered by CP Editor (https://cpeditor.org)
    
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;typedef unsigned long long ull;
    typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD;
    #define I_int ll
    inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
    #define read read()
    #define rep(i, a, b) for(int i=(a);i<=(b);++i)
    #define dep(i, a, b) for(int i=(a);i>=(b);--i)
    ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
    const int maxn=2e5+7,maxm=1e6+7,mod=1e9+7;
    
    char s[maxn];
    int ne[maxn][27],mp[27],dp[maxn][23];
    
    int main(){
    	int m=read,n=read;
    	scanf("%s",s+1);
    	for(int i=0;i<=26;i++) mp[i]=n+1,ne[n][i]=n+1;
    	for(int i=n;i;i--){
    		int now=s[i]-'a';
    		ne[i][now]=mp[now];
    		mp[now]=i;
    		for(int j=0;j<m;j++){
    			ne[i-1][j]=mp[j];
    		}
    	}
    	for(int i=0;i<=n;i++){
    		int now=0;
    		for(int j=0;j<m;j++) now=max(now,ne[i][j]);
    		dp[i][0]=now;
    	}
    	for(int i=0;i<22;i++) dp[n][i]=dp[n+1][i]=n+1;
    	for(int j=1;j<22;j++)
    		for(int i=0;i<=n;i++){
    			dp[i][j]=dp[dp[i][j-1]][j-1];
    		}
    	int q=read;
    	while(q--){
    		int l=read-1,r=read;
    		int ans=1;
    		for(int i=21;i>=0;i--){
    		//	cout<<i<<" "<<l<<" "<<dp[l][i]<<" "<<ans<<endl;
    			if(dp[l][i]<=r){
    				
    				l=dp[l][i];
    				ans=ans+(1<<i);
    			}
    		}
    			
    		cout<<ans<<endl;
    	}
    	
    	
    	return 0;
    }
    

    2020沈阳ICPC D

    点击查看代码
    
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;typedef unsigned long long ull;
    typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD;
    #define I_int ll
    inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
    #define read read()
    #define rep(i, a, b) for(int i=(a);i<=(b);++i)
    #define dep(i, a, b) for(int i=(a);i>=(b);--i)
    ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
    const int maxn=1e6+7;
    
    char s[maxn];
    ll n,ans,sum;
    
    void dfs(int u,int cnt0,int cnt1,int now){
    	if(ans>=100||cnt0>sum||cnt1>sum) return ;
    	if(u==n){
    		cout<<s<<endl;
    		ans++;
    		return ;
    	}
    	if(now%2==0){
    		s[u]='b';
    		dfs(u+1,cnt0+1,cnt1,now);
    		s[u]='r';
    		dfs(u+1,cnt0,cnt1+1,now^1);
    	}
    	else{
    		s[u]='b';
    		dfs(u+1,cnt0,cnt1+1,now);
    		s[u]='r';
    		dfs(u+1,cnt0+1,cnt1,now^1);
    	}
    }
    
    int main(){
    	n=read;
    	sum=(n+1)/2;
    	ll tmp1=(n+1)/2,tmp2=(n+1)/2;
    	if((n+1)%2) sum++,tmp1++;
    	cout<<tmp1*tmp2<<endl;
    	dfs(0,1,0,0);
        return 0;
    }
    /*
    
    */
    
  • 相关阅读:
    struts2 显示表格
    设置eclipse默认编码为UTF-8 Set default encoding to utf-8 in eclipse
    java hibernate +mysql demo
    Java项目引入第三方Jar包
    mysql 常用sql
    C# snaps
    sql server 与mysql差异(innodb)
    系统数据监控
    Twitter Bootstrap Grid System
    设计模式之访问者模式
  • 原文地址:https://www.cnblogs.com/OvOq/p/15534091.html
Copyright © 2011-2022 走看看