Codeforces Beta Round #5

Chat Server's Outgoing Traffic

题意:一个聊天室,+代表有人进去,-代表有人出去,名字:话。问你有人说话的时候要发送多少字节。
直接模拟一下就好了
#include <cstdio>
#include <string>
#include <queue>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define ll __int64
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
char s[110];  
int main()  
{  
    int num=0,sum=0,ans;
    while(gets(s))  
    {  
        if(s[0]=='+')  
            num++;  
        else if(s[0]=='-')  
            num--;  
        else  
        {  
            for(int i=0; i<strlen(s); i++)  
                if(s[i]==':')  
                {  
                    ans=i;  
                    break;  
                }  
            sum+=(strlen(s)-1-ans)*num;  
        }  
    }  
    printf("%d\n",sum);   
}  

Center Alignment

题意:给出多行字符串,让你加边框,如果空格不能平均分配,那么一个靠左,一个靠右。
暴力模拟...
#include <cstdio>
#include <string>
#include <queue>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define ll __int64
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int main()
{
	string s[1005];
	int cnt=0;
	int ma=0;
	while(getline(cin,s[cnt]))
	{
		int len=s[cnt].length();
		ma=max(len,ma);
		cnt++;
	}
	for(int i=0; i<ma+2; i++)
		printf("*");
	puts("");
	int flag=0;
	for(int i=0; i<cnt; i++)
	{
		printf("*");
		int len=ma-s[i].length();
		if(len==ma)
		{
			for(int i=0; i<ma; i++)
				printf(" ");
		}
		else if(len&1)
		{
			if(flag==0)
			{
				flag=!flag;
				for(int j=0; j<len/2; j++)
					printf(" ");
				cout<<s[i];
				for(int j=0; j<=len/2; j++)
					printf(" ");
			}
			else
			{
				flag=!flag;
				for(int j=0; j<=len/2; j++)
					printf(" ");
				cout<<s[i];
				for(int j=0; j<len/2; j++)
					printf(" ");
			}
		}
		else
		{
			for(int j=0; j<len/2; j++)
				printf(" ");
			cout<<s[i];
			for(int j=0; j<len/2; j++)
				printf(" ");
		}
		printf("*");
		puts("");
	}
	for(int i=0; i<ma+2; i++)
		printf("*");
}

Longest Regular Bracket Sequence

题意:给你一个由‘(’‘)’两个符号组成的字符串,求能够配对的最长连续子串的长度和数量。
直接dp...数组开小,.RE了一发..
#include <cstdio>
#include <cstring>
#include <stack>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
char s[1000055];
int dp[1000055]={0};
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    if(s[1]=='('&&s[2]==')')
        dp[2]=2;
    for(int i=3;i<=len;i++)
    {
        if(s[i]==')')
        {
            if(s[i-dp[i-1]-1]=='('&&i-dp[i-1]-1>=1)
            {
                dp[i]=dp[i-1]+2;
                if(dp[i-dp[i]]&&i-dp[i]>=1)
                    dp[i]+=dp[i-dp[i]];
            }
        }
    }
    int maxn=0,maxnum=1;
    for(int i=1;i<=len;i++)
    {
        if(dp[i]>maxn)
        {
            maxnum=1;
            maxn=dp[i];
        }
        else if(dp[i]==maxn&&dp[i]!=0)
            maxnum++;
    }
    printf("%d %d\n",maxn,maxnum);
}

Follow Traffic Rules


题意:长度为l的道路,再d处有一个限速标志,限速为w,车的最大速度为v,加速度为a,当车从速度为0开始启动,最少多少时间能开完这条道路。
高中物理,分类讨论...
代码就不贴了

Bindian Signalizing


题意:有n座围成一个圈的山,站在两个山头能互相看见当且仅当两座山之间没有比他们更高的山,求能互相看见山的对数。

首先要拆环成链,将山的序列改变,第一座山是最高的山。 
其次是统计对于这个序列的L数组和R数组。表示:

  • First hill to the left of the x, which is strictly higher than x. 
  • First hill to the right of the x, which is strictly higher than x.

生成C数组:

  • All hills that are as high as x and are located between x and y.

(来自官方题解)

最后统计答案。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值