zoukankan      html  css  js  c++  java
  • 2016 ICPC 北京

    D - What a Beautiful Lake

    找递增长度递减长度-1

    # include<bits/stdc++.h>
    #define maxn 205
    using namespace std;
    int n;
    int a[maxn];
    int main(){
    	//freopen("in.txt","r",stdin);
    	while(scanf("%d",&n)!=EOF){
    		if(!n) break;
    		for(int i=0;i<n;i++) scanf("%d",&a[i]),a[i+n]=a[i];
    		int res=0;
    		for(int i=0;i<2*n;i++)
    			for(int j=i;j<2*n;j++){
    				bool flg1=1,flg2=1;
    				for(int k=i+1;k<=j;k++){
    					if(a[k]<=a[k-1]) flg1=false;
    					if(a[k]>=a[k-1]) flg2=false;
    				}
    				if(flg1||flg2)
    					res=max(res,j-i);
    			}
    		res=min(res,n-1);
    		cout<<res<<endl;
    	}
    	return 0;
    }
    

    E - What a Ridiculous Election

    双向宽搜。

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    
    int vis[100000][4][3];
    
    struct node{
    	int now,t2,t3,step;
    	node(){}
    	node(int _now,int _t2,int _t3,int _step):now(_now),t2(_t2),t3(_t3),step(_step){}
    };
    
    queue<node> Q;
    
    int base[10],top;
    
    inline int get1(int now,int i){
    	memset(base,0,sizeof base);
    	top=0;
    	while(top<=4){
    		base[++top]=now%10;
    		now/=10;
    	}
    	swap(base[i],base[i+1]);
    	int ret=0;
    	for(int j=5;j>=1;j--)
    		ret=ret*10+base[j];
    	return ret;
    }
    
    inline int get2(int now,int i){
    	memset(base,0,sizeof base);
    	top=0;
    	while(top<=4){
    		base[++top]=now%10;
    		now/=10;
    	}
    	base[i]=(base[i]+1)%10;
    	int ret=0;
    	for(int j=5;j>=1;j--)
    		ret=ret*10+base[j];
    	return ret;
    }
    
    inline int get3(int now,int i){
    	memset(base,0,sizeof base);
    	top=0;
    	while(top<=4){
    		base[++top]=now%10;
    		now/=10;
    	}
    	base[i]=(base[i]*2)%10;
    	int ret=0;
    	for(int j=5;j>=1;j--)
    		ret=ret*10+base[j];
    	return ret;
    }
    
    void init(){
    	memset(vis,63,sizeof vis);
    	Q.push(node(12345,3,2,0));
    	vis[12345][3][2]=0;
    	while(!Q.empty()){
    		int now=Q.front().now;
    		int t2=Q.front().t2;
    		int t3=Q.front().t3;
    		int step=Q.front().step;Q.pop();
    		//cout<<t2<<" "<<t3<<endl;
    		//1
    		for(int i=1;i<=4;i++){
    			int newt=get1(now,i);
    			if(vis[newt][t2][t3]<=step+1) continue;
    			vis[newt][t2][t3]=step+1;
    			Q.push(node(newt,t2,t3,step+1));
    		}
    
    		//2
    		if(t2>0){
    			for(int i=1;i<=5;i++){
    				int newt=get2(now,i);
    				if(vis[newt][t2-1][t3]<=step+1) continue;
    				vis[newt][t2-1][t3]=step+1;
    				Q.push(node(newt,t2-1,t3,step+1));
    			}
    		}
    
    		//3
    		if(t3>0){
    			for(int i=1;i<=5;i++){
    				int newt=get3(now,i);
    				if(vis[newt][t2][t3-1]<=step+1) continue;
    				vis[newt][t2][t3-1]=step+1;
    				Q.push(node(newt,t2,t3-1,step+1));
    			}
    		}
    	}
    }
    
    int main(){
    	//freopen("in.txt","r",stdin);
    	init();
    	//cout<<get1(2345,1)<<endl;
    	int n;char st[20];
    	while(~scanf("%s",&st)){
    		n=0;
    		for(int i=0;i<(int)strlen(st);i++)
    			n=n*10+st[i]-'0';
    		int Min=vis[0][0][0];
    		for(int i=0;i<=3;i++)
    			for(int j=0;j<=2;j++)
    				Min=min(Min,vis[n][i][j]);
    		if(Min==vis[0][0][0]) Min=-1;
    		printf("%d
    ",Min);
    	}
    	return 0;
    }
    

    F - What a Simple Research

    模拟。

    #include <bits/stdc++.h>
    
    using namespace std;
    struct node {
    
    	char c;
    	int num;
    };
    
    bool cmp(node a,node b) {
    	if(a.num==b.num) return a.c<b.c;
    	else return a.num>b.num;
    }
    int m,n;
    node a[10];
    char s[200];
    int main() {
    	//freopen("in.txt","r",stdin);
    	//freopen("out.txt","w",stdout);
    	while(scanf("%d%d",&n,&m)!=EOF) {
    		if(n==0&&m==0) break;
    		a[0].c='A';
    		a[1].c='C';
    		a[2].c='D';
    		a[3].c='E';
    		a[4].c='G';
    		a[0].num=0;
    		a[1].num=0;
    		a[2].num=0;
    		a[3].num=0;
    		a[4].num=0;
    		for(int i=1;i<=n;i++) {
    			scanf("%s",s);
    			//printf("%s
    ",s);
    			for(int j=0;j<m;j++) {
    				if(s[j]=='A') a[0].num++;
    				if(s[j]=='C') a[1].num++;
    				if(s[j]=='D') a[2].num++;
    				if(s[j]=='E') a[3].num++;
    				if(s[j]=='G') a[4].num++;
    			}
    		}
    		sort(a,a+5,cmp);
    		int flg=0;
    		for(int i=0;i<5;i++) {
    			if(a[i].num) {
    				if(flg) printf(" ");
    				flg=1;
    				printf("%c %d",a[i].c,a[i].num);
    			}
    		}
    		printf("
    ");
    	}
    	return 0;
    }
    

    I - A Boring Problem

    前项向后项转移可以有低阶的利用二项式定理展开,需要注意维护的是前缀k次方和,求的是和的k次方。

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const int mod = 1000000007;
    ll C[200][200];
    
    ll pow1[200],pow2[200],pp,p1,p2;
    
    int n,k;
    
    char st[50005];
    ll S[50005];
    ll ans[50005];
    ll PM[50005][105];
    
    void init(){
    	C[0][0]=1;
    	for(int i=1;i<=150;i++){
    		C[i][0]=1;
    		for(int j=1;j<=i;j++)
    			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
    	}
    }
    
    
    int main(){
    	//freopen("in.txt","r",stdin);
    	init();
    	int T;
    	cin>>T;
    	while(T--){
    		scanf("%d%d",&n,&k);
    		scanf("%s",st+1);
    		int len=strlen(st+1);
    		for(int i=1;i<=len;i++)
    			S[i]=S[i-1]+st[i]-'0',PM[i][0]=S[i];
    		for(int i=1;i<=len;i++)
    			for(int j=1;j<=k;j++)
    				PM[i][j]=PM[i][j-1]*PM[i][0]%mod;
    		for(int i=1;i<=len;i++)
    			for(int j=0;j<=k;j++)
    				PM[i][j]=(PM[i][j]+PM[i-1][j])%mod;
    		p1=p2=0;
    		for(int i=1;i<=len;i++){
    			ans[i]=0;
    			p1=S[i];
    			pow1[0]=1;
    			for(ll c=1;c<=k;c++)
    				pow1[c]=pow1[c-1]*p1%mod;
    			ans[i]=pow1[k]*i%mod;
    			for(int c=1;c<=k;c++){
    				ll ft=1;
    				if(c&1) ft=-1;
    				ans[i]=(ans[i]+C[k][c]*pow1[k-c]%mod*PM[i-1][c-1]%mod*ft)%mod;
    			}
    			if(ans[i]<0) ans[i]+=mod;
    		}
    		for(int i=1;i<=n;i++)
    			printf("%lld%c",ans[i]," 
    "[i==n]);
    	}
    	return 0;
    }
    

    K - JiLi Number

    大约到1e9的时候就几乎没有这类数了,打表找出来。

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    
    const ll d[100]={
     0
    ,1
    ,199981
    ,199982
    ,199983
    ,199984
    ,199985
    ,199986
    ,199987
    ,199988
    ,199989
    ,199990
    ,200000
    ,200001
    ,1599981
    ,1599982
    ,1599983
    ,1599984
    ,1599985
    ,1599986
    ,1599987
    ,1599988
    ,1599989
    ,1599990
    ,2600000
    ,2600001
    ,13199998
    ,35000000
    ,35000001
    ,35199981
    ,35199982
    ,35199983
    ,35199984
    ,35199985
    ,35199986
    ,35199987
    ,35199988
    ,35199989
    ,35199990
    ,35200000
    ,35200001
    ,117463825
    ,500000000
    ,500000001
    ,500199981
    ,500199982
    ,500199983
    ,500199984
    ,500199985
    ,500199986
    ,500199987
    ,500199988
    ,500199989
    ,500199990
    ,500200000
    ,500200001
    ,501599981
    ,501599982
    ,501599983
    ,501599984
    ,501599985
    ,501599986
    ,501599987
    ,501599988
    ,501599989
    ,501599990
    ,502600000
    ,502600001
    ,513199998
    ,535000000
    ,535000001
    ,535199981
    ,535199982
    ,535199983
    ,535199984
    ,535199985
    ,535199986
    ,535199987
    ,535199988
    ,535199989
    ,535199990
    ,535200000
    ,535200001
    ,1111111110
    };
    
    int main(){
    	//freopen("in.txt","r",stdin);
    	char st[205];
    	while(~scanf("%s",st)){
    		int len = strlen(st);
    		if(len>11){
    			puts("83 1111111110");
    			continue;
    		}
    		ll n=0;
    		for(int i=0;i<len;i++)
    			n=n*10+st[i]-'0';
    		int k=83;
    		for(;k>=1;k--){
    			if(d[k]<=n) break;
    		}
    		printf("%d %lld
    ",k,d[k]);
    	}
    	return 0;
    }
    
  • 相关阅读:
    HTML5新特性,新的 Input 类型
    HTML5新特性,拖放(Drag 和 Drop)
    剑指 Offer 32
    剑指 Offer 28. 对称的二叉树
    993. 二叉树的堂兄弟节点
    897. 递增顺序查找树
    872. 叶子相似的树
    637. 二叉树的层平均值
    617. 合并二叉树
    559. N叉树的最大深度
  • 原文地址:https://www.cnblogs.com/foreignbill/p/7875902.html
Copyright © 2011-2022 走看看