zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 93 (Rated for Div. 2)

    Problems

    # Name
    A Bad Trianglestandard input/output1 s, 256 MB Submit Add to favourites img x13120
    B Substring Removal Gamestandard input/output2 s, 256 MB Submit Add to favourites img x12487
    C Good Subarraysstandard input/output2 s, 256 MB Submit Add to favourites img x3758
    D Colored Rectanglesstandard input/output2 s, 256 MB Submit Add to favourites img x2467
    E Two Types of Spellsstandard input/output3.5 s, 256 MB Submit Add to favourites img x449
    F Controversial Roundsstandard input/output2 s, 256 MB Submit Add to favourites img x139
    G Running Competitionstandard input/output2 s, 512 MB Submit Add to favourites img x68

    Solution

    A

    #pragma GCC optimize(2)
    #include<set>
    #include<map>
    #include<ctime>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define rint register int
    typedef long long LL;
    typedef unsigned long long ULL;
    using namespace std;
    const int N=5e4+5;
    int T,n;
    int a[N];
    int main()
    {
    //	freopen("1.in","r",stdin);
    	int i;
    	scanf("%d",&T);
    	while(T--) {
    		scanf("%d",&n);
    		for(i=1;i<=n;i++)
    			scanf("%d",&a[i]);
    		if(a[1]+a[2]<=a[n]) 
    			printf("1 2 %d
    ",n);
    		else printf("-1
    ");
    	}
    	return 0;
    }
    

    B

    #pragma GCC optimize(2)
    #include<set>
    #include<map>
    #include<ctime>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define rint register int
    typedef long long LL;
    typedef unsigned long long ULL;
    using namespace std;
    const int N=256;
    int T,n;
    char a[N];
    vector<int> v;
    int main()
    {
    //	freopen("1.in","r",stdin);
    	int i;
    	scanf("%d",&T);
    	while(T--) {
    		scanf("%s",a+1);
    		n=strlen(a+1);
    		v.clear();
    		int cnt=0;
    		for(i=1;i<=n;i++) {
    			if(a[i]=='1') cnt++;
    			else {
    				if(cnt>0) v.push_back(cnt);	
    				cnt=0;	
    			}
    		}
    		if(cnt>0) v.push_back(cnt);
    		sort(v.begin(),v.end(),greater<int>());
    		int ans=0;
    		for(i=0;i<(int)v.size();i+=2) 
    			ans+=v[i];
    		printf("%d
    ",ans);
    	}
    	return 0;
    }
    

    C

    //#pragma GCC optimize(2)
    #include<set>
    #include<map>
    #include<ctime>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define rint register int
    typedef long long LL;
    typedef unsigned long long ULL;
    using namespace std;
    const int N=1e5+5;
    int T,n;
    char c[N];
    int a[N],p[N];
    LL f[N];
    map<int,int> M;
    void calc()
    {
    	int cha=0;
    	M.clear();
    	for(int i=1;i<=n;i++) {
    		if(a[i]==0) p[i]=i;
    		else if(M.count(-a[i]-cha)) 
    			p[i]=M[-a[i]-cha];
    		cha+=a[i];
    		M[a[i]-cha]=i;
    	}
    	return;
    }
    int main()
    {
    //	freopen("1.in","r",stdin);
    	int i;
    	scanf("%d",&T);
    	while(T--) {
    		scanf("%d",&n);
    		scanf("%s",c+1);
    		for(i=1;i<=n;i++) 
    			a[i]=(c[i]-'0')-1;
    		
    		memset(p,0,sizeof p);
    		memset(f,0,sizeof f);
    		calc();
    		for(i=1;i<=n;i++) {
    			if(p[i]!=0)
    				f[i]=f[p[i]-1]+1;
    		}
    		LL ans=0;
    		for(i=1;i<=n;i++) ans+=f[i];
    		cout<<ans<<endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    new和malloc的区别
    C++中的数据类型强制转换方法
    C++中pair和make_pair的区别
    PlantUML 图绘制类库--VSCODE插件
    Exception: HOUR_OF_DAY: 0 -> 1的问题
    Fiddler手机抓包工具如何设置过滤域名
    MySQL 正则表达式 REGEXP
    ASP.NET Web API 2 中的属性路由
    windows服务搭建(VS2019创建Windows服务不显示安装组件)
    JWT的验证(转载)
  • 原文地址:https://www.cnblogs.com/cjl-world/p/13508568.html
Copyright © 2011-2022 走看看